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)
6 #ifndef TT_HAS_PREFIX_OPERATORS_HPP
7 #define TT_HAS_PREFIX_OPERATORS_HPP
9 #if defined(__GNUC__) && (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__ > 40900)
10 #pragma GCC diagnostic push
11 #pragma GCC diagnostic ignored "-Wunused-function"
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)
25 struct internal { ret operator BOOST_TT_TRAIT_OP () const; };
28 inline ret operator BOOST_TT_TRAIT_OP (const external&){ return ret(); }
30 struct comma1_ret { };
31 struct ret_with_comma1 { comma1_ret operator,(int); };
33 struct internal_comma1 { ret_with_comma1 operator BOOST_TT_TRAIT_OP () const; };
35 struct external_comma1 { };
36 inline ret_with_comma1 operator BOOST_TT_TRAIT_OP (const external_comma1&){ return ret_with_comma1(); }
38 struct ret_with_comma2 { void operator,(int); };
40 struct internal_comma2 { ret_with_comma2 operator BOOST_TT_TRAIT_OP () const; };
42 struct external_comma2 { };
43 inline ret_with_comma2 operator BOOST_TT_TRAIT_OP (const external_comma2&){ return ret_with_comma2(); }
45 struct returns_int { int operator BOOST_TT_TRAIT_OP (); };
47 struct returns_void { void operator BOOST_TT_TRAIT_OP (); };
49 struct returns_void_star { void *operator BOOST_TT_TRAIT_OP (); };
51 struct returns_double { double operator BOOST_TT_TRAIT_OP (); };
54 struct convertible_to_ret1 { operator ret1 () const; };
55 struct returns_convertible_to_ret1 { convertible_to_ret1 operator BOOST_TT_TRAIT_OP (); };
57 struct convertible_to_ret2 { };
58 struct ret2 { ret2(const convertible_to_ret2); };
59 struct returns_convertible_to_ret2 { convertible_to_ret2 operator BOOST_TT_TRAIT_OP (); };
62 class Derived1 : public Base1 { };
64 inline bool operator BOOST_TT_TRAIT_OP (const Base1&) { return true; }
67 struct Derived2 : public Base2 {
68 Derived2(int); // to check if it works with a class that is not default constructible
71 bool operator BOOST_TT_TRAIT_OP (const Derived2&) { return true; }
75 //class internal_private { ret operator BOOST_TT_TRAIT_OP () const; };
79 TEST_TR(void, void, false);
80 TEST_TR(void, int, false);
82 TEST_T(without, false);
83 TEST_T(internal, true);
84 TEST_T(external, true);
85 TEST_T(internal_comma1, true);
86 TEST_T(external_comma1, true);
87 TEST_T(internal_comma2, true);
88 TEST_T(external_comma2, true);
89 TEST_T(returns_int, true);
90 TEST_T(returns_void, true);
91 TEST_T(returns_void_star, true);
92 TEST_T(returns_double, true);
93 TEST_T(returns_convertible_to_ret1, true);
94 TEST_T(returns_convertible_to_ret2, true);
96 TEST_T(Derived1, true);
98 TEST_T(Derived2, true);
100 TEST_TR(without, void, false);
101 TEST_TR(without, bool, false);
102 TEST_TR(internal_comma1, void, false);
103 TEST_TR(internal_comma1, bool, false);
104 TEST_TR(internal_comma1, ret_with_comma1, true);
105 TEST_TR(internal_comma2, void, false);
106 TEST_TR(internal_comma2, bool, false);
107 TEST_TR(internal_comma2, ret_with_comma2, true);
108 TEST_TR(external, void, false);
109 TEST_TR(external, bool, false);
110 TEST_TR(external, ret, true);
111 TEST_TR(returns_int, void, false);
112 TEST_TR(returns_int, bool, true);
113 TEST_TR(returns_int, int, true);
114 TEST_TR(returns_void, void, true);
115 TEST_TR(returns_void, bool, false);
116 TEST_TR(returns_void_star, bool, true);
117 TEST_TR(returns_double, void, false);
118 TEST_TR(returns_double, bool, true);
119 TEST_TR(returns_double, double, true);
120 TEST_TR(returns_convertible_to_ret1, void, false);
121 TEST_TR(returns_convertible_to_ret1, ret1, true);
122 TEST_TR(returns_convertible_to_ret2, ret2, true);
123 TEST_TR(Base1, bool, true);
124 TEST_TR(Derived1, bool, true);
125 TEST_TR(Base2, bool, false);
126 TEST_TR(Derived2, bool, true);
127 // compile time error
128 // TEST_T(internal_private, false);
133 #if defined(__GNUC__) && (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__ > 40900)
134 #pragma GCC diagnostic pop