has_member_qualifiers.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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_member_qualifiers.hpp>
  10. #include "test.hpp"
  11. #ifdef BOOST_CLBL_TRTS_DISABLE_REFERENCE_QUALIFIERS
  12. int main() { return 0; }
  13. #else
  14. struct foo {};
  15. template<typename T>
  16. void assert_qualified() {
  17. CT_ASSERT( has_member_qualifiers<T>::value);
  18. }
  19. template<typename T>
  20. void assert_unqualified() {
  21. CT_ASSERT(! has_member_qualifiers<T>::value);
  22. }
  23. int main() {
  24. {
  25. using f = void(foo::*)();
  26. using l = void(foo::*)() &;
  27. using r = void(foo::*)() && ;
  28. using c = void(foo::*)() const;
  29. using cl = void(foo::*)() const &;
  30. using cr = void(foo::*)() const &&;
  31. using v = void(foo::*)() volatile;
  32. using vl = void(foo::*)() volatile &;
  33. using vr = void(foo::*)() volatile &&;
  34. using cv = void(foo::*)() const volatile;
  35. using cvl = void(foo::*)() const volatile &;
  36. using cvr = void(foo::*)() const volatile &&;
  37. assert_unqualified<f>();
  38. assert_qualified<l>();
  39. assert_qualified<r>();
  40. assert_qualified<c>();
  41. assert_qualified<cl>();
  42. assert_qualified<cr>();
  43. assert_qualified<v>();
  44. assert_qualified<vl>();
  45. assert_qualified<vr>();
  46. assert_qualified<cv>();
  47. assert_qualified<cvl>();
  48. assert_qualified<cvr>();
  49. }
  50. {
  51. struct f { int operator()() { return 0; } };
  52. struct l { int operator()() & { return 0; } };
  53. struct r { int operator()() && { return 0; } };
  54. struct c { int operator()() const { return 0; } };
  55. struct cl { int operator()() const & { return 0; } };
  56. struct cr { int operator()() const && { return 0; } };
  57. struct v { int operator()() volatile { return 0; } };
  58. struct vl { int operator()() volatile & { return 0; } };
  59. struct vr { int operator()() volatile && { return 0; } };
  60. struct cv { int operator()() const volatile { return 0; } };
  61. struct cvl { int operator()() const volatile & { return 0; } };
  62. struct cvr { int operator()() const volatile && { return 0; } };
  63. assert_unqualified<f>();
  64. assert_qualified<l>();
  65. assert_qualified<r>();
  66. assert_qualified<c>();
  67. assert_qualified<cl>();
  68. assert_qualified<cr>();
  69. assert_qualified<v>();
  70. assert_qualified<vl>();
  71. assert_qualified<vr>();
  72. assert_qualified<cv>();
  73. assert_qualified<cvl>();
  74. assert_qualified<cvr>();
  75. }
  76. #ifndef BOOST_CLBL_TRTS_DISABLE_ABOMINABLE_FUNCTIONS
  77. {
  78. using f = void();
  79. using l = void() &;
  80. using r = void() && ;
  81. using c = void() const;
  82. using cl = void() const &;
  83. using cr = void() const &&;
  84. using v = void() volatile;
  85. using vl = void() volatile &;
  86. using vr = void() volatile &&;
  87. using cv = void() const volatile;
  88. using cvl = void() const volatile &;
  89. using cvr = void() const volatile &&;
  90. CT_ASSERT(! has_member_qualifiers<f>());
  91. CT_ASSERT( has_member_qualifiers<l>());
  92. CT_ASSERT( has_member_qualifiers<r>());
  93. CT_ASSERT( has_member_qualifiers<c>());
  94. CT_ASSERT( has_member_qualifiers<cl>());
  95. CT_ASSERT( has_member_qualifiers<cr>());
  96. CT_ASSERT( has_member_qualifiers<v>());
  97. CT_ASSERT( has_member_qualifiers<vl>());
  98. CT_ASSERT( has_member_qualifiers<vr>());
  99. CT_ASSERT( has_member_qualifiers<cv>());
  100. CT_ASSERT( has_member_qualifiers<cvl>());
  101. CT_ASSERT( has_member_qualifiers<cvr>());
  102. }
  103. #endif //#ifndef BOOST_CLBL_TRTS_DISABLE_ABOMINABLE_FUNCTIONS
  104. using f_ptr = void(*)();
  105. assert_unqualified<f_ptr>();
  106. assert_unqualified<f_ptr foo::*>();
  107. assert_unqualified<int foo::*>();
  108. assert_unqualified<void(&)()>();
  109. }
  110. #endif //#ifdef BOOST_CLBL_TRTS_DISABLE_REFERENCE_QUALIFIERS