fork download
  1. namespace std { class type_info; }
  2. typedef char yes_type;
  3. struct no_type { char padding[8]; };
  4.  
  5. #include <iostream>
  6. #include <type_traits>
  7.  
  8. template< typename _1 >
  9. struct EqualityComparable
  10. {
  11. struct requires0 {
  12. template< typename T >
  13. static yes_type check (
  14. T a, T b,
  15. char (*) [sizeof(decltype( bool{a == b} ))]
  16. );
  17. template< typename T >
  18. static no_type check ( ... );
  19.  
  20. template< typename T >
  21. struct sizeof_check {
  22. T a; T b;
  23. static size_t const value = sizeof check<_1>(a , b , 0);
  24. };
  25.  
  26. static bool const value = sizeof(yes_type) ==
  27. sizeof_check< _1 >::value;
  28. };
  29. static bool const value = requires0::value;
  30. };
  31.  
  32. template<typename T> void print_type()
  33. {
  34. std::cout << __PRETTY_FUNCTION__ << std::endl;
  35. }
  36.  
  37. template<typename T>
  38. struct remove_refs
  39. {
  40. typedef T type;
  41. };
  42.  
  43.  
  44. template<typename T>
  45. struct remove_refs<T&&>
  46. {
  47. typedef T type;
  48. };
  49.  
  50.  
  51. template<typename T>
  52. struct remove_refs<T&>
  53. {
  54. typedef T type;
  55. };
  56.  
  57. int main ( void )
  58. {
  59. std::cout << EqualityComparable<int>::value << std::endl; // 1 -- ok
  60. std::cout << EqualityComparable<std::common_type<int>::type>::value
  61. << std::endl; // 1 -- ok
  62. std::cout << EqualityComparable<std::common_type<int, int>::type>::value
  63. << std::endl; // 0 -- why??
  64. std::cout << EqualityComparable<remove_refs<std::common_type<int, int>::type>::type>::value
  65. << std::endl; // 1 -- OK on Clang too
  66. print_type<std::common_type<int, int>::type>(); // GCC - int, Clang - int&&
  67. print_type<remove_refs<std::common_type<int, int>::type>::type>(); // GCC - int, Clang - int
  68. return 0;
  69. }
Success #stdin #stdout 0s 2884KB
stdin
Standard input is empty
stdout
1
1
1
1
void print_type() [with T = int]
void print_type() [with T = int]