fork download
  1. #include <iostream>
  2. #include <type_traits>
  3. #include <typeinfo>
  4.  
  5. enum MyType
  6. {
  7. A,
  8. B
  9. };
  10.  
  11. template<MyType>
  12. struct MyStruct {
  13. MyStruct(int, double){};
  14. };
  15.  
  16. template<MyType type>
  17. MyStruct<type> createMyStruct()
  18. {
  19. return {0, 1.1};
  20. }
  21.  
  22. int main()
  23. {
  24. auto structA = createMyStruct<A>();
  25. auto structB = createMyStruct<B>();
  26.  
  27. std::cout << typeid(structA).name() << std::endl;
  28. std::cout << typeid(structB).name() << std::endl;
  29. }
Success #stdin #stdout 0s 3140KB
stdin
Standard input is empty
stdout
8MyStructIL6MyType0EE
8MyStructIL6MyType1EE