1 /* 2 Copyright Barrett Adair 2016-2017 3 Distributed under the Boost Software License, Version 1.0. 4 (See accompanying file LICENSE.md or copy at http ://boost.org/LICENSE_1_0.txt) 5 */ 6 7 #include <type_traits> 8 #include <functional> 9 #include <utility> 10 #include <boost/callable_traits/has_varargs.hpp> 11 #include "test.hpp" 12 13 struct foo {}; 14 15 template<typename T> assert_has_varargs()16void assert_has_varargs() { 17 18 CT_ASSERT( has_varargs<T>::value); 19 } 20 21 template<typename T> assert_not_has_varargs()22void assert_not_has_varargs() { 23 24 CT_ASSERT(! has_varargs<T>::value); 25 } 26 27 main()28int main() { 29 30 { 31 using f = void(foo::*)(); 32 using l = void(foo::*)() LREF; 33 using r = void(foo::*)() RREF ; 34 using c = void(foo::*)() const; 35 using cl = void(foo::*)() const LREF; 36 using cr = void(foo::*)() const RREF; 37 using v = void(foo::*)() volatile; 38 using vl = void(foo::*)() volatile LREF; 39 using vr = void(foo::*)() volatile RREF; 40 using cv = void(foo::*)() const volatile; 41 using cvl = void(foo::*)() const volatile LREF; 42 using cvr = void(foo::*)() const volatile RREF; 43 44 assert_not_has_varargs<f>(); 45 assert_not_has_varargs<l>(); 46 assert_not_has_varargs<r>(); 47 assert_not_has_varargs<c>(); 48 assert_not_has_varargs<cl>(); 49 assert_not_has_varargs<cr>(); 50 assert_not_has_varargs<v>(); 51 assert_not_has_varargs<vl>(); 52 assert_not_has_varargs<vr>(); 53 assert_not_has_varargs<cv>(); 54 assert_not_has_varargs<cvl>(); 55 assert_not_has_varargs<cvr>(); 56 } 57 58 { 59 //a member data pointer to a function pointer 60 //is not treated like a member function pointer 61 using f_ptr = void(*)(...); 62 using f = f_ptr foo::*; 63 assert_not_has_varargs<f>(); 64 } 65 66 { 67 using f = void(BOOST_CLBL_TRTS_DEFAULT_VARARGS_CC foo::*)(...); 68 using l = void(BOOST_CLBL_TRTS_DEFAULT_VARARGS_CC foo::*)(...) LREF; 69 using r = void(BOOST_CLBL_TRTS_DEFAULT_VARARGS_CC foo::*)(...) RREF ; 70 using c = void(BOOST_CLBL_TRTS_DEFAULT_VARARGS_CC foo::*)(...) const; 71 using cl = void(BOOST_CLBL_TRTS_DEFAULT_VARARGS_CC foo::*)(...) const LREF; 72 using cr = void(BOOST_CLBL_TRTS_DEFAULT_VARARGS_CC foo::*)(...) const RREF; 73 using v = void(BOOST_CLBL_TRTS_DEFAULT_VARARGS_CC foo::*)(...) volatile; 74 using vl = void(BOOST_CLBL_TRTS_DEFAULT_VARARGS_CC foo::*)(...) volatile LREF; 75 using vr = void(BOOST_CLBL_TRTS_DEFAULT_VARARGS_CC foo::*)(...) volatile RREF; 76 using cv = void(BOOST_CLBL_TRTS_DEFAULT_VARARGS_CC foo::*)(...) const volatile; 77 using cvl = void(BOOST_CLBL_TRTS_DEFAULT_VARARGS_CC foo::*)(...) const volatile LREF; 78 using cvr = void(BOOST_CLBL_TRTS_DEFAULT_VARARGS_CC foo::*)(...) const volatile RREF; 79 80 assert_has_varargs<f>(); 81 assert_has_varargs<l>(); 82 assert_has_varargs<r>(); 83 assert_has_varargs<c>(); 84 assert_has_varargs<cl>(); 85 assert_has_varargs<cr>(); 86 assert_has_varargs<v>(); 87 assert_has_varargs<vl>(); 88 assert_has_varargs<vr>(); 89 assert_has_varargs<cv>(); 90 assert_has_varargs<cvl>(); 91 assert_has_varargs<cvr>(); 92 } 93 94 { 95 struct f { int operator()() { return 0; } }; 96 struct l { int operator()() LREF { return 0; } }; 97 struct r { int operator()() RREF { return 0; } }; 98 struct c { int operator()() const { return 0; } }; 99 struct cl { int operator()() const LREF { return 0; } }; 100 struct cr { int operator()() const RREF { return 0; } }; 101 struct v { int operator()() volatile { return 0; } }; 102 struct vl { int operator()() volatile LREF { return 0; } }; 103 struct vr { int operator()() volatile RREF { return 0; } }; 104 struct cv { int operator()() const volatile { return 0; } }; 105 struct cvl { int operator()() const volatile LREF { return 0; } }; 106 struct cvr { int operator()() const volatile RREF { return 0; } }; 107 108 assert_not_has_varargs<f>(); 109 assert_not_has_varargs<l>(); 110 assert_not_has_varargs<r>(); 111 assert_not_has_varargs<c>(); 112 assert_not_has_varargs<cl>(); 113 assert_not_has_varargs<cr>(); 114 assert_not_has_varargs<v>(); 115 assert_not_has_varargs<vl>(); 116 assert_not_has_varargs<vr>(); 117 assert_not_has_varargs<cv>(); 118 assert_not_has_varargs<cvl>(); 119 assert_not_has_varargs<cvr>(); 120 } 121 122 { 123 struct f { int operator()(...) { return 0; } }; 124 struct l { int operator()(...) LREF { return 0; } }; 125 struct r { int operator()(...) RREF { return 0; } }; 126 struct c { int operator()(...) const { return 0; } }; 127 struct cl { int operator()(...) const LREF { return 0; } }; 128 struct cr { int operator()(...) const RREF { return 0; } }; 129 struct v { int operator()(...) volatile { return 0; } }; 130 struct vl { int operator()(...) volatile LREF { return 0; } }; 131 struct vr { int operator()(...) volatile RREF { return 0; } }; 132 struct cv { int operator()(...) const volatile { return 0; } }; 133 struct cvl { int operator()(...) const volatile LREF { return 0; } }; 134 struct cvr { int operator()(...) const volatile RREF { return 0; } }; 135 136 assert_has_varargs<f>(); 137 assert_has_varargs<l>(); 138 assert_has_varargs<r>(); 139 assert_has_varargs<c>(); 140 assert_has_varargs<cl>(); 141 assert_has_varargs<cr>(); 142 assert_has_varargs<v>(); 143 assert_has_varargs<vl>(); 144 assert_has_varargs<vr>(); 145 assert_has_varargs<cv>(); 146 assert_has_varargs<cvl>(); 147 assert_has_varargs<cvr>(); 148 } 149 150 #ifndef BOOST_CLBL_TRTS_DISABLE_ABOMINABLE_FUNCTIONS 151 152 { 153 using f = void(); 154 using l = void() LREF; 155 using r = void() RREF ; 156 using c = void() const; 157 using cl = void() const LREF; 158 using cr = void() const RREF; 159 using v = void() volatile; 160 using vl = void() volatile LREF; 161 using vr = void() volatile RREF; 162 using cv = void() const volatile; 163 using cvl = void() const volatile LREF; 164 using cvr = void() const volatile RREF; 165 166 CT_ASSERT(! has_varargs<f>()); 167 CT_ASSERT(! has_varargs<l>()); 168 CT_ASSERT(! has_varargs<r>()); 169 CT_ASSERT(! has_varargs<c>()); 170 CT_ASSERT(! has_varargs<cl>()); 171 CT_ASSERT(! has_varargs<cr>()); 172 CT_ASSERT(! has_varargs<v>()); 173 CT_ASSERT(! has_varargs<vl>()); 174 CT_ASSERT(! has_varargs<vr>()); 175 CT_ASSERT(! has_varargs<cv>()); 176 CT_ASSERT(! has_varargs<cvl>()); 177 CT_ASSERT(! has_varargs<cvr>()); 178 } 179 180 { 181 using f = void(...); 182 using l = void(...) LREF; 183 using r = void(...) RREF ; 184 using c = void(...) const; 185 using cl = void(...) const LREF; 186 using cr = void(...) const RREF; 187 using v = void(...) volatile; 188 using vl = void(...) volatile LREF; 189 using vr = void(...) volatile RREF; 190 using cv = void(...) const volatile; 191 using cvl = void(...) const volatile LREF; 192 using cvr = void(...) const volatile RREF; 193 194 CT_ASSERT( has_varargs<f>()); 195 CT_ASSERT( has_varargs<l>()); 196 CT_ASSERT( has_varargs<r>()); 197 CT_ASSERT( has_varargs<c>()); 198 CT_ASSERT( has_varargs<cl>()); 199 CT_ASSERT( has_varargs<cr>()); 200 CT_ASSERT( has_varargs<v>()); 201 CT_ASSERT( has_varargs<vl>()); 202 CT_ASSERT( has_varargs<vr>()); 203 CT_ASSERT( has_varargs<cv>()); 204 CT_ASSERT( has_varargs<cvl>()); 205 CT_ASSERT( has_varargs<cvr>()); 206 } 207 208 #endif //#ifndef BOOST_CLBL_TRTS_DISABLE_ABOMINABLE_FUNCTIONS 209 210 assert_not_has_varargs<void(*)()>(); 211 assert_has_varargs<void(*)(...)>(); 212 assert_not_has_varargs<void(&)()>(); 213 assert_has_varargs<void(&)(...)>(); 214 } 215