add_member_lvalue_reference.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. @Copyright Barrett Adair 2015-2018
  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_LVALUE_REFERENCE_HPP
  7. #define BOOST_CLBL_TRTS_ADD_MEMBER_LVALUE_REFERENCE_HPP
  8. #include <boost/callable_traits/detail/core.hpp>
  9. namespace boost { namespace callable_traits {
  10. //[ add_member_lvalue_reference_hpp
  11. /*`
  12. [section:ref_add_member_lvalue_reference add_member_lvalue_reference]
  13. [heading Header]
  14. ``#include <boost/callable_traits/add_member_lvalue_reference.hpp>``
  15. [heading Definition]
  16. */
  17. //<-
  18. #ifdef BOOST_CLBL_TRTS_DISABLE_REFERENCE_QUALIFIERS
  19. template<typename T>
  20. struct add_member_lvalue_reference_t {
  21. static_assert(std::is_same<T, detail::dummy>::value,
  22. "Reference member qualifiers are not supported by this configuration.");
  23. };
  24. #else
  25. //->
  26. template<typename T>
  27. using add_member_lvalue_reference_t = //see below
  28. //<-
  29. #ifdef BOOST_CLBL_TRTS_DISABLE_ABOMINABLE_FUNCTIONS
  30. detail::sfinae_try<
  31. typename detail::traits<T>::add_member_lvalue_reference,
  32. detail::fail_when_same<typename detail::traits<T>::add_member_lvalue_reference,
  33. detail::abominable_functions_not_supported_on_this_compiler,
  34. this_compiler_doesnt_support_abominable_function_types>,
  35. detail::fail_if_invalid<
  36. typename detail::traits<T>::add_member_lvalue_reference,
  37. member_qualifiers_are_illegal_for_this_type>>;
  38. #else
  39. detail::try_but_fail_if_invalid<
  40. typename detail::traits<T>::add_member_lvalue_reference,
  41. member_qualifiers_are_illegal_for_this_type>;
  42. #endif // #ifdef BOOST_CLBL_TRTS_DISABLE_ABOMINABLE_FUNCTIONS
  43. #endif // #ifdef BOOST_CLBL_TRTS_DISABLE_REFERENCE_QUALIFIERS
  44. namespace detail {
  45. template<typename T, typename = std::false_type>
  46. struct add_member_lvalue_reference_impl {};
  47. template<typename T>
  48. struct add_member_lvalue_reference_impl <T, typename std::is_same<
  49. add_member_lvalue_reference_t<T>, detail::dummy>::type>
  50. {
  51. using type = add_member_lvalue_reference_t<T>;
  52. };
  53. }
  54. //->
  55. template<typename T>
  56. struct add_member_lvalue_reference
  57. : detail::add_member_lvalue_reference_impl<T> {};
  58. //<-
  59. }} // namespace boost::callable_traits
  60. //->
  61. /*`
  62. [heading Constraints]
  63. * `T` must be a function type or a member function pointer type
  64. * If `T` is a pointer, it may not be cv/ref qualified
  65. [heading Behavior]
  66. * A substitution failure occurs if the constraints are violated.
  67. * Adds a member lvalue reference qualifier (`&`) to `T`, if not already present.
  68. * If an rvalue reference qualifier is present, the lvalue reference qualifier replaces it (in accordance with reference collapsing rules).
  69. [heading Input/Output Examples]
  70. [table
  71. [[`T`] [`add_member_lvalue_reference_t<T>`]]
  72. [[`int()`] [`int() &`]]
  73. [[`int(foo::*)()`] [`int(foo::*)() &`]]
  74. [[`int(foo::*)() &`] [`int(foo::*)() &`]]
  75. [[`int(foo::*)() &&`] [`int(foo::*)() &`]]
  76. [[`int(foo::*)() const`] [`int(foo::*)() const &`]]
  77. [[`int(foo::*)() transaction_safe`] [`int(foo::*)() & transaction_safe`]]
  78. [[`int`] [(substitution failure)]]
  79. [[`int (&)()`] [(substitution failure)]]
  80. [[`int (*)()`] [(substitution failure)]]
  81. [[`int foo::*`] [(substitution failure)]]
  82. [[`int (foo::* const)()`] [(substitution failure)]]
  83. ]
  84. [heading Example Program]
  85. [import ../example/add_member_lvalue_reference.cpp]
  86. [add_member_lvalue_reference]
  87. [endsect]
  88. */
  89. //]
  90. #endif