is_const_member.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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/is_const_member.hpp>
  10. #include "test.hpp"
  11. struct foo {};
  12. template<typename T>
  13. void assert_const_qualified() {
  14. CT_ASSERT( is_const_member<T>());
  15. }
  16. template<typename T>
  17. void assert_not_const_qualified() {
  18. CT_ASSERT(! is_const_member<T>());
  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_const_qualified<f>();
  35. assert_not_const_qualified<l>();
  36. assert_not_const_qualified<r>();
  37. assert_const_qualified<c>();
  38. assert_const_qualified<cl>();
  39. assert_const_qualified<cr>();
  40. assert_not_const_qualified<v>();
  41. assert_not_const_qualified<vl>();
  42. assert_not_const_qualified<vr>();
  43. assert_const_qualified<cv>();
  44. assert_const_qualified<cvl>();
  45. assert_const_qualified<cvr>();
  46. }
  47. {
  48. struct f { int operator()() { return 0; } };
  49. struct l { int operator()() LREF { return 0; } };
  50. struct r { int operator()() RREF { return 0; } };
  51. struct c { int operator()() const { return 0; } };
  52. struct cl { int operator()() const LREF { return 0; } };
  53. struct cr { int operator()() const RREF { return 0; } };
  54. struct v { int operator()() volatile { return 0; } };
  55. struct vl { int operator()() volatile LREF { return 0; } };
  56. struct vr { int operator()() volatile RREF { return 0; } };
  57. struct cv { int operator()() const volatile { return 0; } };
  58. struct cvl { int operator()() const volatile LREF { return 0; } };
  59. struct cvr { int operator()() const volatile RREF { return 0; } };
  60. assert_not_const_qualified<f>();
  61. assert_not_const_qualified<l>();
  62. assert_not_const_qualified<r>();
  63. assert_const_qualified<c>();
  64. assert_const_qualified<cl>();
  65. assert_const_qualified<cr>();
  66. assert_not_const_qualified<v>();
  67. assert_not_const_qualified<vl>();
  68. assert_not_const_qualified<vr>();
  69. assert_const_qualified<cv>();
  70. assert_const_qualified<cvl>();
  71. assert_const_qualified<cvr>();
  72. }
  73. #ifndef BOOST_CLBL_TRTS_DISABLE_ABOMINABLE_FUNCTIONS
  74. {
  75. using f = void();
  76. using l = void() LREF;
  77. using r = void() RREF ;
  78. using c = void() const;
  79. using cl = void() const LREF;
  80. using cr = void() const RREF;
  81. using v = void() volatile;
  82. using vl = void() volatile LREF;
  83. using vr = void() volatile RREF;
  84. using cv = void() const volatile;
  85. using cvl = void() const volatile LREF;
  86. using cvr = void() const volatile RREF;
  87. CT_ASSERT(! is_const_member<f>());
  88. CT_ASSERT(! is_const_member<l>());
  89. CT_ASSERT(! is_const_member<r>());
  90. CT_ASSERT( is_const_member<c>());
  91. CT_ASSERT( is_const_member<cl>());
  92. CT_ASSERT( is_const_member<cr>());
  93. CT_ASSERT(! is_const_member<v>());
  94. CT_ASSERT(! is_const_member<vl>());
  95. CT_ASSERT(! is_const_member<vr>());
  96. CT_ASSERT( is_const_member<cv>());
  97. CT_ASSERT( is_const_member<cvl>());
  98. CT_ASSERT( is_const_member<cvr>());
  99. }
  100. #endif
  101. using f_ptr = void(*)();
  102. assert_not_const_qualified<f_ptr>();
  103. assert_not_const_qualified<f_ptr foo::*>();
  104. assert_not_const_qualified<int foo::*>();
  105. assert_not_const_qualified<void(&)()>();
  106. }