Last active
April 9, 2017 15:48
-
-
Save Axure/ca03fd5a32cfc39f108a3bf0a5d55a26 to your computer and use it in GitHub Desktop.
Revisions
-
Hu Zheng revised this gist
Apr 9, 2017 . 1 changed file with 15 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,20 +1,32 @@ #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 } -
Hu Zheng created this gist
Apr 9, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ #include <iostream> struct MyTrait; template <class ... Traits> struct MyTypeWithTrait {}; template< template<typename ...> class TypeWithTrait > void impledFunc(TypeWithTrait<MyTrait> entity) { // do something. std::cout << "I'm fooed by C++\n"; } int main() { MyTypeWithTrait<MyTrait> myEntity; impledFunc(myEntity); MyTypeWithTrait<> myRubbishEntity; impledFunc(myRubbishEntity); // Won't compile }