fork download
  1. #include <iostream>
  2. #include <type_traits>
  3.  
  4. struct A
  5. {
  6. A(int a) { std::cout << a << "\n"; }
  7. };
  8.  
  9. struct B
  10. {
  11. B(int a) { std::cout << -a << "\n"; }
  12. };
  13.  
  14. template<bool>
  15. struct policy;
  16.  
  17. template<>
  18. struct policy<true> { typedef A type; };
  19.  
  20. template<>
  21. struct policy<false> { typedef B type; };
  22.  
  23. template<typename T>
  24. struct C : public policy<std::is_polymorphic<T>::value>::type
  25. {
  26. typedef typename policy<std::is_polymorphic<T>::value>::type Base;
  27. C() : Base(5) {}
  28. };
  29.  
  30. int main()
  31. {
  32. C<int> a; // should print -5
  33. C<std::ostream> b; // should print 5
  34. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
-5
5