has_varargs.cpp 7.8 KB

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