fork download
  1. #include <cassert>
  2.  
  3. template<typename T1, typename T2>
  4. struct is_same
  5. {
  6. static const bool value = false;
  7. };
  8.  
  9. template<typename T>
  10. struct is_same<T,T>
  11. {
  12. static const bool value = true;
  13. };
  14.  
  15. template<typename F, typename Arg1>
  16. struct parameter_type
  17. {
  18. // what goes here?
  19. };
  20.  
  21. struct takes_int
  22. {
  23. void operator()(int);
  24. };
  25.  
  26. struct takes_float_ref
  27. {
  28. char operator()(float &);
  29. };
  30.  
  31. struct takes_float_cref
  32. {
  33. int operator()(const float &);
  34. };
  35.  
  36. struct bar {};
  37.  
  38. struct something_convertible_to_bar
  39. {
  40. operator bar ();
  41. };
  42.  
  43. struct takes_bar
  44. {
  45. bar operator()(bar);
  46. };
  47.  
  48. struct takes_value
  49. {
  50. template<typename T> void operator()(T);
  51. };
  52.  
  53. struct has_overloads
  54. {
  55. bar operator()(int &);
  56.  
  57. void operator()(const int &);
  58. };
  59.  
  60. int main()
  61. {
  62. // int
  63. assert((is_same<
  64. parameter_type<takes_int, unsigned int>::type,
  65. int
  66. >::value));
  67.  
  68. // float &
  69. assert((is_same<
  70. parameter_type<takes_float_ref, float>::type,
  71. float &
  72. >::value));
  73.  
  74. // const float &
  75. assert((is_same<
  76. parameter_type<takes_float_cref, int>::type,
  77. const float &
  78. >::value));
  79.  
  80. // bar
  81. assert((is_same<
  82. parameter_type<takes_bar, something_convertible_to_bar>::type,
  83. bar
  84. >::value));
  85.  
  86. // int
  87. assert((is_same<
  88. parameter_type<takes_value, int &>::type,
  89. int
  90. >::value));
  91.  
  92. // const int &
  93. assert((is_same<
  94. parameter_type<has_overloads, const int &>::type,
  95. const int &
  96. >::value));
  97.  
  98. return 0;
  99. }
  100.  
  101.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:63: error: ‘type’ is not a member of ‘parameter_type<takes_int, unsigned int>’
prog.cpp:63: error: ‘type’ is not a member of ‘parameter_type<takes_int, unsigned int>’
prog.cpp:63: error: template argument 1 is invalid
prog.cpp:69: error: ‘type’ is not a member of ‘parameter_type<takes_float_ref, float>’
prog.cpp:69: error: ‘type’ is not a member of ‘parameter_type<takes_float_ref, float>’
prog.cpp:69: error: template argument 1 is invalid
prog.cpp:75: error: ‘type’ is not a member of ‘parameter_type<takes_float_cref, int>’
prog.cpp:75: error: ‘type’ is not a member of ‘parameter_type<takes_float_cref, int>’
prog.cpp:75: error: template argument 1 is invalid
prog.cpp:81: error: ‘type’ is not a member of ‘parameter_type<takes_bar, something_convertible_to_bar>’
prog.cpp:81: error: ‘type’ is not a member of ‘parameter_type<takes_bar, something_convertible_to_bar>’
prog.cpp:81: error: template argument 1 is invalid
prog.cpp:87: error: ‘type’ is not a member of ‘parameter_type<takes_value, int&>’
prog.cpp:87: error: ‘type’ is not a member of ‘parameter_type<takes_value, int&>’
prog.cpp:87: error: template argument 1 is invalid
prog.cpp:93: error: ‘type’ is not a member of ‘parameter_type<has_overloads, const int&>’
prog.cpp:93: error: ‘type’ is not a member of ‘parameter_type<has_overloads, const int&>’
prog.cpp:93: error: template argument 1 is invalid
stdout
Standard output is empty