Skip to content

Instantly share code, notes, and snippets.

@Axure
Last active April 9, 2017 15:48
Show Gist options
  • Save Axure/ca03fd5a32cfc39f108a3bf0a5d55a26 to your computer and use it in GitHub Desktop.
Save Axure/ca03fd5a32cfc39f108a3bf0a5d55a26 to your computer and use it in GitHub Desktop.
Rusty C++
#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