fork download
  1. #include <memory>
  2. #include <iostream>
  3.  
  4.  
  5. template <typename V, typename W>
  6. struct foobar
  7. { static const int value = 0; };
  8.  
  9. template <typename V>
  10. struct foobar<V, typename std::conditional<1==sizeof(V), std::true_type, std::false_type>::type>
  11. { static const int value = 1; };
  12.  
  13. template <typename V>
  14. struct foobar<V, typename std::conditional<4==sizeof(V), std::true_type, std::false_type>::type>
  15. { static const int value = 4; };
  16.  
  17. int main()
  18. {
  19. int result = 0;
  20. result = foobar<char, std::true_type>::value;
  21. result = foobar<short, std::true_type>::value;
  22. result = foobar<int, std::true_type>::value;
  23. std::cout << "char : " << foobar<char, std::true_type>::value << std::endl;
  24. std::cout << "short : " << foobar<short, std::true_type>::value << std::endl;
  25. std::cout << "int : " << foobar<int, std::true_type>::value << std::endl;
  26. return 0;
  27. }
  28.  
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
char : 1
short : 0
int : 4