has_prefix_operators.hpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // (C) Copyright Frederic Bron 2009-2011.
  2. // Use, modification and distribution are subject to the
  3. // Boost Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef TT_HAS_PREFIX_OPERATORS_HPP
  6. #define TT_HAS_PREFIX_OPERATORS_HPP
  7. #if defined(__GNUC__) && (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__ > 40900)
  8. #pragma GCC diagnostic push
  9. #pragma GCC diagnostic ignored "-Wunused-function"
  10. #endif
  11. // It would be nice to get rid of the unnamed namespace here,
  12. // but for now we just turn off inspection reporting :(
  13. // boostinspect:nounnamed
  14. // test with one template parameter
  15. #define TEST_T(TYPE,RESULT) BOOST_CHECK_INTEGRAL_CONSTANT((::boost::BOOST_TT_TRAIT_NAME<TYPE>::value), RESULT)
  16. // test with one template parameter plus return value
  17. #define TEST_TR(TYPE,RET,RESULT) BOOST_CHECK_INTEGRAL_CONSTANT((::boost::BOOST_TT_TRAIT_NAME<TYPE,RET>::value), RESULT)
  18. namespace {
  19. struct without { };
  20. struct ret { };
  21. struct internal { ret operator BOOST_TT_TRAIT_OP () const; };
  22. struct external { };
  23. inline ret operator BOOST_TT_TRAIT_OP (const external&){ return ret(); }
  24. struct comma1_ret { };
  25. struct ret_with_comma1 { comma1_ret operator,(int); };
  26. struct internal_comma1 { ret_with_comma1 operator BOOST_TT_TRAIT_OP () const; };
  27. struct external_comma1 { };
  28. inline ret_with_comma1 operator BOOST_TT_TRAIT_OP (const external_comma1&){ return ret_with_comma1(); }
  29. struct ret_with_comma2 { void operator,(int); };
  30. struct internal_comma2 { ret_with_comma2 operator BOOST_TT_TRAIT_OP () const; };
  31. struct external_comma2 { };
  32. inline ret_with_comma2 operator BOOST_TT_TRAIT_OP (const external_comma2&){ return ret_with_comma2(); }
  33. struct returns_int { int operator BOOST_TT_TRAIT_OP (); };
  34. struct returns_void { void operator BOOST_TT_TRAIT_OP (); };
  35. struct returns_void_star { void *operator BOOST_TT_TRAIT_OP (); };
  36. struct returns_double { double operator BOOST_TT_TRAIT_OP (); };
  37. struct ret1 { };
  38. struct convertible_to_ret1 { operator ret1 () const; };
  39. struct returns_convertible_to_ret1 { convertible_to_ret1 operator BOOST_TT_TRAIT_OP (); };
  40. struct convertible_to_ret2 { };
  41. struct ret2 { ret2(const convertible_to_ret2); };
  42. struct returns_convertible_to_ret2 { convertible_to_ret2 operator BOOST_TT_TRAIT_OP (); };
  43. class Base1 { };
  44. class Derived1 : public Base1 { };
  45. inline bool operator BOOST_TT_TRAIT_OP (const Base1&) { return true; }
  46. class Base2 { };
  47. struct Derived2 : public Base2 {
  48. Derived2(int); // to check if it works with a class that is not default constructible
  49. };
  50. bool operator BOOST_TT_TRAIT_OP (const Derived2&) { return true; }
  51. struct tag { };
  52. //class internal_private { ret operator BOOST_TT_TRAIT_OP () const; };
  53. void common() {
  54. TEST_T(void, false);
  55. TEST_TR(void, void, false);
  56. TEST_TR(void, int, false);
  57. TEST_T(without, false);
  58. TEST_T(internal, true);
  59. TEST_T(external, true);
  60. TEST_T(internal_comma1, true);
  61. TEST_T(external_comma1, true);
  62. TEST_T(internal_comma2, true);
  63. TEST_T(external_comma2, true);
  64. TEST_T(returns_int, true);
  65. TEST_T(returns_void, true);
  66. TEST_T(returns_void_star, true);
  67. TEST_T(returns_double, true);
  68. TEST_T(returns_convertible_to_ret1, true);
  69. TEST_T(returns_convertible_to_ret2, true);
  70. TEST_T(Base1, true);
  71. TEST_T(Derived1, true);
  72. TEST_T(Base2, false);
  73. TEST_T(Derived2, true);
  74. TEST_TR(without, void, false);
  75. TEST_TR(without, bool, false);
  76. TEST_TR(internal_comma1, void, false);
  77. TEST_TR(internal_comma1, bool, false);
  78. TEST_TR(internal_comma1, ret_with_comma1, true);
  79. TEST_TR(internal_comma2, void, false);
  80. TEST_TR(internal_comma2, bool, false);
  81. TEST_TR(internal_comma2, ret_with_comma2, true);
  82. TEST_TR(external, void, false);
  83. TEST_TR(external, bool, false);
  84. TEST_TR(external, ret, true);
  85. TEST_TR(returns_int, void, false);
  86. TEST_TR(returns_int, bool, true);
  87. TEST_TR(returns_int, int, true);
  88. TEST_TR(returns_void, void, true);
  89. TEST_TR(returns_void, bool, false);
  90. TEST_TR(returns_void_star, bool, true);
  91. TEST_TR(returns_double, void, false);
  92. TEST_TR(returns_double, bool, true);
  93. TEST_TR(returns_double, double, true);
  94. TEST_TR(returns_convertible_to_ret1, void, false);
  95. TEST_TR(returns_convertible_to_ret1, ret1, true);
  96. TEST_TR(returns_convertible_to_ret2, ret2, true);
  97. TEST_TR(Base1, bool, true);
  98. TEST_TR(Derived1, bool, true);
  99. TEST_TR(Base2, bool, false);
  100. TEST_TR(Derived2, bool, true);
  101. // compile time error
  102. // TEST_T(internal_private, false);
  103. }
  104. }
  105. #if defined(__GNUC__) && (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__ > 40900)
  106. #pragma GCC diagnostic pop
  107. #endif
  108. #endif