add_member_const.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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_ADD_MEMBER_CONST_HPP
  7. #define BOOST_CLBL_TRTS_ADD_MEMBER_CONST_HPP
  8. #include <boost/callable_traits/detail/core.hpp>
  9. namespace boost { namespace callable_traits {
  10. //[ add_member_const_hpp
  11. /*`
  12. [section:ref_add_member_const add_member_const]
  13. [heading Header]
  14. ``#include <boost/callable_traits/add_member_const.hpp>``
  15. [heading Definition]
  16. */
  17. template<typename T>
  18. using add_member_const_t = //see below
  19. //<-
  20. #ifdef BOOST_CLBL_TRTS_DISABLE_ABOMINABLE_FUNCTIONS
  21. detail::sfinae_try<
  22. typename detail::traits<T>::add_member_const,
  23. detail::fail_when_same<typename detail::traits<T>::add_member_const,
  24. detail::abominable_functions_not_supported_on_this_compiler,
  25. this_compiler_doesnt_support_abominable_function_types>,
  26. detail::fail_if_invalid<typename detail::traits<T>::add_member_const,
  27. member_qualifiers_are_illegal_for_this_type>>;
  28. #else
  29. detail::try_but_fail_if_invalid<
  30. typename detail::traits<T>::add_member_const,
  31. member_qualifiers_are_illegal_for_this_type>;
  32. #endif // #ifdef BOOST_CLBL_TRTS_DISABLE_ABOMINABLE_FUNCTIONS
  33. namespace detail {
  34. template<typename T, typename = std::false_type>
  35. struct add_member_const_impl {};
  36. template<typename T>
  37. struct add_member_const_impl <T, typename std::is_same<
  38. add_member_const_t<T>, detail::dummy>::type>
  39. {
  40. using type = add_member_const_t<T>;
  41. };
  42. }
  43. //->
  44. template<typename T>
  45. struct add_member_const : detail::add_member_const_impl<T> {};
  46. //<-
  47. }} // namespace boost::callable_traits
  48. //->
  49. /*`
  50. [heading Constraints]
  51. * `T` must be a function type or a member function pointer type
  52. * If `T` is a pointer, it may not be cv/ref qualified
  53. [heading Behavior]
  54. * A substitution failure occurs if the constraints are violated.
  55. * Adds a member `const` qualifier to `T`, if not already present.
  56. [heading Input/Output Examples]
  57. [table
  58. [[`T`] [`add_member_const_t<T>`]]
  59. [[`int()`] [`int() const`]]
  60. [[`int(foo::*)()`] [`int(foo::*)() const`]]
  61. [[`int(foo::*)() &`] [`int(foo::*)() const &`]]
  62. [[`int(foo::*)() &&`] [`int(foo::*)() const &&`]]
  63. [[`int(foo::*)() const`] [`int(foo::*)() const`]]
  64. [[`int(foo::*)() volatile`] [`int(foo::*)() const volatile`]]
  65. [[`int(foo::*)() transaction_safe`] [`int(foo::*)() const transaction_safe`]]
  66. [[`int`] [(substitution failure)]]
  67. [[`int (&)()`] [(substitution failure)]]
  68. [[`int (*)()`] [(substitution failure)]]
  69. [[`int foo::*`] [(substitution failure)]]
  70. [[`int (foo::* const)()`] [(substitution failure)]]
  71. ]
  72. [heading Example Program]
  73. [import ../example/add_member_const.cpp]
  74. [add_member_const]
  75. [endsect]
  76. */
  77. //]
  78. #endif // #ifndef BOOST_CLBL_TRTS_ADD_MEMBER_CONST_HPP