is_const_member.hpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. @Copyright Barrett Adair 2015-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. #ifndef BOOST_CLBL_TRTS_IS_CONST_MEMBER_HPP
  7. #define BOOST_CLBL_TRTS_IS_CONST_MEMBER_HPP
  8. #include <boost/callable_traits/detail/core.hpp>
  9. namespace boost { namespace callable_traits {
  10. //[ is_const_member_hpp
  11. /*`[section:ref_is_const_member is_const_member]
  12. [heading Header]
  13. ``#include <boost/callable_traits/is_const_member.hpp>``
  14. [heading Definition]
  15. */
  16. // inherits from either std::true_type or std::false_type
  17. template<typename T>
  18. struct is_const_member;
  19. //<-
  20. template<typename T>
  21. struct is_const_member
  22. : detail::traits<detail::shallow_decay<T>>::is_const_member {
  23. using type = typename detail::traits<
  24. detail::shallow_decay<T>>::is_const_member;
  25. };
  26. #ifdef BOOST_CLBL_TRTS_DISABLE_VARIABLE_TEMPLATES
  27. template<typename T>
  28. struct is_const_member_v {
  29. static_assert(std::is_same<T, detail::dummy>::value,
  30. "Variable templates not supported on this compiler.");
  31. };
  32. #else
  33. //->
  34. // only available when variable templates are supported
  35. template<typename T>
  36. //<-
  37. BOOST_CLBL_TRAITS_INLINE_VAR
  38. //->
  39. constexpr bool is_const_member_v = //see below
  40. //<-
  41. detail::traits<detail::shallow_decay<T>>::is_const_member::value;
  42. #endif
  43. }} // namespace boost::callable_traits
  44. //->
  45. /*`
  46. [heading Constraints]
  47. * none
  48. [heading Behavior]
  49. * `is_const_member<T>::value` is `true` when either:
  50. * `T` is a function type with a `const` member qualifier
  51. * `T` is a pointer to a member function with a `const` member qualifier
  52. * `T` is a function object with a non-overloaded `operator()`, where the `operator()` has a `const` member qualifier
  53. * On compilers that support variable templates, `is_const_member_v<T>` is equivalent to `is_const_member<T>::value`.
  54. [heading Input/Output Examples]
  55. [table
  56. [[`T`] [`is_const_member_v<T>`]]
  57. [[`int() const`] [`true`]]
  58. [[`int() const volatile`] [`true`]]
  59. [[`int() const & transaction_safe`] [`true`]]
  60. [[`int() const &&`] [`true`]]
  61. [[`int(foo::*&)() const`] [`true`]]
  62. [[`int(foo::*)() const volatile`] [`true`]]
  63. [[`int(foo::*)() const volatile &&`][`true`]]
  64. [[`int(foo::* const)() const`] [`true`]]
  65. [[`int()`] [`false`]]
  66. [[`int() volatile`] [`false`]]
  67. [[`int() &&`] [`false`]]
  68. [[`int(*)()`] [`false`]]
  69. [[`int`] [`false`]]
  70. [[`int foo::*`] [`false`]]
  71. [[`const int foo::*`] [`false`]]
  72. ]
  73. [heading Example Program]
  74. [import ../example/is_const_member.cpp]
  75. [is_const_member]
  76. [endsect]
  77. */
  78. //]
  79. #endif // #ifndef BOOST_CLBL_TRTS_IS_CONST_MEMBER_HPP