fork(1) download
  1. #include <iostream>
  2. #include <type_traits>
  3.  
  4. struct base { };
  5. struct derived : base { };
  6. struct anotherbase { };
  7. struct anotherderived : anotherbase { };
  8.  
  9. template<typename T, bool = std::is_base_of<base, T>::value
  10. || std::is_base_of<anotherbase, T>::value>
  11. struct Type { };
  12.  
  13. template<typename T>
  14. struct Type<T, true>
  15. {
  16. typedef float mytype;
  17. };
  18.  
  19. int main()
  20. {
  21. Type<base>::mytype a1 = 4.2f;
  22. Type<anotherderived>::mytype a2 = 8.4f;
  23. std::cout << a1 << '\n' << a2 << '\n';
  24. }
Success #stdin #stdout 0s 2884KB
stdin
Standard input is empty
stdout
4.2
8.4