fork download
  1. #include <iostream>
  2.  
  3. struct my_abstract_class { virtual int x() = 0; };
  4. struct my_incomplete_class;
  5.  
  6. template<typename T> struct is_array
  7. { static const bool value = false; };
  8.  
  9. template<typename T> struct is_array<T[]>
  10. { static const bool value = true; };
  11.  
  12. template<typename T, size_t n> struct is_array<T[n]>
  13. { static const bool value = true; };
  14.  
  15. template<typename T> struct is_reference
  16. { static const bool value = false; };
  17.  
  18. template<typename T> struct is_reference<T&>
  19. { static const bool value = true; };
  20.  
  21. template<typename T> struct is_void
  22. { static const bool value = false; };
  23.  
  24. template<> struct is_void<void>
  25. { static const bool value = true; };
  26.  
  27. template<> struct is_void<void const>
  28. { static const bool value = true; };
  29.  
  30. template<> struct is_void<void volatile>
  31. { static const bool value = true; };
  32.  
  33. template<> struct is_void<void const volatile>
  34. { static const bool value = true; };
  35.  
  36. template<typename T>
  37. class is_abstract_class_or_function
  38. {
  39. typedef char (&Two)[2];
  40. template<typename U> static char test(U(*)[1]);
  41. template<typename U> static Two test(...);
  42.  
  43. public:
  44. static const bool value =
  45. !is_reference<T>::value &&
  46. !is_void<T>::value &&
  47. (sizeof(test<T>(0)) == sizeof(Two));
  48. };
  49.  
  50. template<typename T> struct is_returnable
  51. { static const bool value = !is_array<T>::value && !is_abstract_class_or_function<T>::value; };
  52.  
  53. int main()
  54. {
  55. ::std::cout
  56. << is_returnable<int>::value << ::std::endl
  57. << is_returnable<int[]>::value << ::std::endl
  58. << is_returnable<int[2]>::value << ::std::endl
  59. << is_returnable<int()>::value << ::std::endl
  60. << is_returnable<my_abstract_class>::value << ::std::endl
  61. << is_returnable<my_incomplete_class>::value << ::std::endl
  62. ;
  63. return 0;
  64. }
Success #stdin #stdout 0s 2684KB
stdin
Standard input is empty
stdout
1
0
0
0
0
1