tag.hpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. // Copyright David Abrahams 2005.
  2. // Copyright Cromwell D. Enage 2017.
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. #ifndef BOOST_PARAMETER_AUX_TAG_DWA2005610_HPP
  7. #define BOOST_PARAMETER_AUX_TAG_DWA2005610_HPP
  8. #include <boost/parameter/aux_/unwrap_cv_reference.hpp>
  9. #include <boost/parameter/aux_/tagged_argument.hpp>
  10. #include <boost/parameter/config.hpp>
  11. #if defined(BOOST_PARAMETER_CAN_USE_MP11) && \
  12. !BOOST_WORKAROUND(BOOST_MSVC, >= 1910)
  13. // MSVC-14.1+ assigns rvalue references to tagged_argument instances
  14. // instead of tagged_argument_rref instances with this code.
  15. #include <boost/mp11/integral.hpp>
  16. #include <boost/mp11/utility.hpp>
  17. #include <type_traits>
  18. namespace boost { namespace parameter { namespace aux {
  19. template <typename Keyword, typename Arg>
  20. struct tag_if_lvalue_reference
  21. {
  22. using type = ::boost::parameter::aux::tagged_argument_list_of_1<
  23. ::boost::parameter::aux::tagged_argument<
  24. Keyword
  25. , typename ::boost::parameter::aux
  26. ::unwrap_cv_reference<Arg>::type
  27. >
  28. >;
  29. };
  30. template <typename Keyword, typename Arg>
  31. struct tag_if_scalar
  32. {
  33. using type = ::boost::parameter::aux::tagged_argument_list_of_1<
  34. ::boost::parameter::aux
  35. ::tagged_argument<Keyword,typename ::std::add_const<Arg>::type>
  36. >;
  37. };
  38. template <typename Keyword, typename Arg>
  39. using tag_if_otherwise = ::boost::mp11::mp_if<
  40. ::std::is_scalar<typename ::std::remove_const<Arg>::type>
  41. , ::boost::parameter::aux::tag_if_scalar<Keyword,Arg>
  42. , ::boost::mp11::mp_identity<
  43. ::boost::parameter::aux::tagged_argument_list_of_1<
  44. ::boost::parameter::aux::tagged_argument_rref<Keyword,Arg>
  45. >
  46. >
  47. >;
  48. template <typename Keyword, typename Arg>
  49. using tag = ::boost::mp11::mp_if<
  50. ::boost::mp11::mp_if<
  51. ::std::is_lvalue_reference<Arg>
  52. , ::boost::mp11::mp_true
  53. , ::boost::parameter::aux::is_cv_reference_wrapper<Arg>
  54. >
  55. , ::boost::parameter::aux::tag_if_lvalue_reference<Keyword,Arg>
  56. , ::boost::parameter::aux::tag_if_otherwise<Keyword,Arg>
  57. >;
  58. }}} // namespace boost::parameter::aux_
  59. #elif defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING)
  60. #include <boost/mpl/bool.hpp>
  61. #include <boost/mpl/if.hpp>
  62. #include <boost/mpl/eval_if.hpp>
  63. #include <boost/mpl/identity.hpp>
  64. #include <boost/type_traits/add_const.hpp>
  65. #include <boost/type_traits/is_scalar.hpp>
  66. #include <boost/type_traits/is_lvalue_reference.hpp>
  67. #include <boost/type_traits/remove_const.hpp>
  68. namespace boost { namespace parameter { namespace aux {
  69. template <typename Keyword, typename ActualArg>
  70. struct tag
  71. {
  72. typedef typename ::boost::parameter::aux
  73. ::unwrap_cv_reference<ActualArg>::type Arg;
  74. typedef typename ::boost::add_const<Arg>::type ConstArg;
  75. typedef typename ::boost::remove_const<Arg>::type MutArg;
  76. typedef typename ::boost::mpl::eval_if<
  77. typename ::boost::mpl::if_<
  78. ::boost::is_lvalue_reference<ActualArg>
  79. , ::boost::mpl::true_
  80. , ::boost::parameter::aux::is_cv_reference_wrapper<ActualArg>
  81. >::type
  82. , ::boost::mpl::identity<
  83. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  84. ::boost::parameter::aux::tagged_argument_list_of_1<
  85. #endif
  86. ::boost::parameter::aux::tagged_argument<Keyword,Arg>
  87. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  88. >
  89. #endif
  90. >
  91. , ::boost::mpl::if_<
  92. ::boost::is_scalar<MutArg>
  93. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  94. , ::boost::parameter::aux::tagged_argument_list_of_1<
  95. ::boost::parameter::aux::tagged_argument<Keyword,ConstArg>
  96. >
  97. , ::boost::parameter::aux::tagged_argument_list_of_1<
  98. ::boost::parameter::aux::tagged_argument_rref<Keyword,Arg>
  99. >
  100. #else
  101. , ::boost::parameter::aux::tagged_argument<Keyword,ConstArg>
  102. , ::boost::parameter::aux::tagged_argument_rref<Keyword,Arg>
  103. #endif
  104. >
  105. >::type type;
  106. };
  107. }}} // namespace boost::parameter::aux_
  108. #else // !defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING)
  109. namespace boost { namespace parameter { namespace aux {
  110. template <
  111. typename Keyword
  112. , typename Arg
  113. #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
  114. , typename = typename ::boost::parameter::aux
  115. ::is_cv_reference_wrapper<Arg>::type
  116. #endif
  117. >
  118. struct tag
  119. {
  120. typedef ::boost::parameter::aux::tagged_argument<
  121. Keyword
  122. , typename ::boost::parameter::aux::unwrap_cv_reference<Arg>::type
  123. > type;
  124. };
  125. }}} // namespace boost::parameter::aux_
  126. #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
  127. #include <boost/mpl/bool.hpp>
  128. #include <boost/type_traits/remove_reference.hpp>
  129. namespace boost { namespace parameter { namespace aux {
  130. template <typename Keyword, typename Arg>
  131. struct tag<Keyword,Arg,::boost::mpl::false_>
  132. {
  133. typedef ::boost::parameter::aux::tagged_argument<
  134. Keyword
  135. , typename ::boost::remove_reference<Arg>::type
  136. > type;
  137. };
  138. }}} // namespace boost::parameter::aux_
  139. #endif // Borland workarounds needed.
  140. #endif // MP11 or perfect forwarding support
  141. #endif // include guard