Last active
April 9, 2017 15:48
-
-
Save Axure/ca03fd5a32cfc39f108a3bf0a5d55a26 to your computer and use it in GitHub Desktop.
Rusty C++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
struct MyTrait; | |
struct AnotherTrait; | |
struct YetAnotherTrait; | |
struct RubbishTrait; | |
template <class ... Traits> | |
struct MyTypeWithTrait {}; | |
template< template<typename ...> class TypeWithTrait, class ... OtherTraits > | |
void impledFunc(TypeWithTrait<MyTrait, OtherTraits...> entity) { | |
// do something. | |
std::cout << "I'm fooed by C++\n"; | |
} | |
template< template<typename ...> class TypeWithTrait, class HeadTrait, class ... OtherTraits > | |
void impledFunc(TypeWithTrait<HeadTrait, OtherTraits...> entity) { | |
// do something. | |
impledFunc(*reinterpret_cast<MyTypeWithTrait<OtherTraits...>* >(&entity)); | |
} | |
int main() { | |
MyTypeWithTrait<MyTrait> myEntity; | |
impledFunc(myEntity); | |
MyTypeWithTrait<YetAnotherTrait, AnotherTrait, MyTrait, RubbishTrait> myAnotherEntity; | |
impledFunc(myAnotherEntity); | |
MyTypeWithTrait<YetAnotherTrait, AnotherTrait, RubbishTrait> myRubbishEntity; | |
impledFunc(myRubbishEntity); // Won't compile | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment