fork download
  1. #include <type_traits>
  2. #include <typeinfo>
  3. #include <iostream>
  4.  
  5. struct tag1 {};
  6. struct tag2 {};
  7.  
  8. // function declaration
  9. std::true_type has_hoge(tag1);
  10. std::false_type has_hoge(tag2);
  11.  
  12. template<bool cond, typename int_type>
  13. struct convert;
  14.  
  15. template<typename int_type>
  16. struct convert<true, int_type>
  17. {
  18. typedef typename std::make_signed<int_type>::type type;
  19. };
  20.  
  21. template<typename int_type>
  22. struct convert<false, int_type>
  23. {
  24. typedef typename std::make_unsigned<int_type>::type type;
  25. };
  26.  
  27. // int
  28. convert<decltype(has_hoge(tag1()))::type::value, int>::type int_hoge;
  29.  
  30. // unsigned int
  31. convert<decltype(has_hoge(tag2()))::type::value, int>::type uint_hoge;
  32.  
  33. // コンパイルエラーになる。
  34. template<typename tag, typename int_type>
  35. struct hogehoge
  36. {
  37. typedef typename convert<decltype(has_hoge(tag()))::type::value, int_type>::type type;
  38. };
  39. // */
  40.  
  41. int main()
  42. {
  43. std::cout << std::is_same<hogehoge<tag2, int>::type, unsigned int>::value;
  44. return 0;
  45. }
  46.  
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
1