set_value_free.hpp 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. //
  2. // traits/set_value_free.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef BOOST_ASIO_TRAITS_SET_VALUE_FREE_HPP
  11. #define BOOST_ASIO_TRAITS_SET_VALUE_FREE_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/config.hpp>
  16. #include <boost/asio/detail/type_traits.hpp>
  17. #include <boost/asio/detail/variadic_templates.hpp>
  18. #if defined(BOOST_ASIO_HAS_DECLTYPE) \
  19. && defined(BOOST_ASIO_HAS_NOEXCEPT) \
  20. && defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE)
  21. # define BOOST_ASIO_HAS_DEDUCED_SET_VALUE_FREE_TRAIT 1
  22. #endif // defined(BOOST_ASIO_HAS_DECLTYPE)
  23. // && defined(BOOST_ASIO_HAS_NOEXCEPT)
  24. // && defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE)
  25. #include <boost/asio/detail/push_options.hpp>
  26. namespace boost {
  27. namespace asio {
  28. namespace traits {
  29. template <typename T, typename Vs, typename = void>
  30. struct set_value_free_default;
  31. template <typename T, typename Vs, typename = void>
  32. struct set_value_free;
  33. } // namespace traits
  34. namespace detail {
  35. struct no_set_value_free
  36. {
  37. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = false);
  38. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
  39. };
  40. #if defined(BOOST_ASIO_HAS_DEDUCED_SET_VALUE_FREE_TRAIT)
  41. template <typename T, typename Vs, typename = void>
  42. struct set_value_free_trait : no_set_value_free
  43. {
  44. };
  45. #if defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
  46. template <typename T, typename... Vs>
  47. struct set_value_free_trait<T, void(Vs...),
  48. typename void_type<
  49. decltype(set_value(declval<T>(), declval<Vs>()...))
  50. >::type>
  51. {
  52. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
  53. using result_type = decltype(
  54. set_value(declval<T>(), declval<Vs>()...));
  55. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = noexcept(
  56. set_value(declval<T>(), declval<Vs>()...)));
  57. };
  58. #else // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
  59. template <typename T>
  60. struct set_value_free_trait<T, void(),
  61. typename void_type<
  62. decltype(set_value(declval<T>()))
  63. >::type>
  64. {
  65. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
  66. using result_type = decltype(set_value(declval<T>()));
  67. BOOST_ASIO_STATIC_CONSTEXPR(bool,
  68. is_noexcept = noexcept(set_value(declval<T>())));
  69. };
  70. #define BOOST_ASIO_PRIVATE_SET_VALUE_FREE_TRAIT_DEF(n) \
  71. template <typename T, BOOST_ASIO_VARIADIC_TPARAMS(n)> \
  72. struct set_value_free_trait<T, void(BOOST_ASIO_VARIADIC_TARGS(n)), \
  73. typename void_type< \
  74. decltype(set_value(declval<T>(), BOOST_ASIO_VARIADIC_DECLVAL(n))) \
  75. >::type> \
  76. { \
  77. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true); \
  78. \
  79. using result_type = decltype( \
  80. set_value(declval<T>(), BOOST_ASIO_VARIADIC_DECLVAL(n))); \
  81. \
  82. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = noexcept( \
  83. set_value(declval<T>(), BOOST_ASIO_VARIADIC_DECLVAL(n)))); \
  84. }; \
  85. /**/
  86. BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_SET_VALUE_FREE_TRAIT_DEF)
  87. #undef BOOST_ASIO_PRIVATE_SET_VALUE_FREE_TRAIT_DEF
  88. #endif // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
  89. #else // defined(BOOST_ASIO_HAS_DEDUCED_SET_VALUE_FREE_TRAIT)
  90. template <typename T, typename Vs, typename = void>
  91. struct set_value_free_trait;
  92. #if defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
  93. template <typename T, typename... Vs>
  94. struct set_value_free_trait<T, void(Vs...)> :
  95. conditional<
  96. is_same<T, typename remove_reference<T>::type>::value
  97. && conjunction<is_same<Vs, typename decay<Vs>::type>...>::value,
  98. typename conditional<
  99. is_same<T, typename add_const<T>::type>::value,
  100. no_set_value_free,
  101. traits::set_value_free<typename add_const<T>::type, void(Vs...)>
  102. >::type,
  103. traits::set_value_free<
  104. typename remove_reference<T>::type,
  105. void(typename decay<Vs>::type...)>
  106. >::type
  107. {
  108. };
  109. #else // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
  110. template <typename T>
  111. struct set_value_free_trait<T, void()> :
  112. conditional<
  113. is_same<T, typename remove_reference<T>::type>::value,
  114. typename conditional<
  115. is_same<T, typename add_const<T>::type>::value,
  116. no_set_value_free,
  117. traits::set_value_free<typename add_const<T>::type, void()>
  118. >::type,
  119. traits::set_value_free<typename remove_reference<T>::type, void()>
  120. >::type
  121. {
  122. };
  123. #define BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME(n) \
  124. BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_##n
  125. #define BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_1 \
  126. && is_same<T1, typename decay<T1>::type>::value
  127. #define BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_2 \
  128. BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_1 \
  129. && is_same<T2, typename decay<T2>::type>::value
  130. #define BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_3 \
  131. BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_2 \
  132. && is_same<T3, typename decay<T3>::type>::value
  133. #define BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_4 \
  134. BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_3 \
  135. && is_same<T4, typename decay<T4>::type>::value
  136. #define BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_5 \
  137. BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_4 \
  138. && is_same<T5, typename decay<T5>::type>::value
  139. #define BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_6 \
  140. BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_5 \
  141. && is_same<T6, typename decay<T6>::type>::value
  142. #define BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_7 \
  143. BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_6 \
  144. && is_same<T7, typename decay<T7>::type>::value
  145. #define BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_8 \
  146. BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_7 \
  147. && is_same<T8, typename decay<T8>::type>::value
  148. #define BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_TRAIT_DEF(n) \
  149. template <typename T, BOOST_ASIO_VARIADIC_TPARAMS(n)> \
  150. struct set_value_free_trait<T, void(BOOST_ASIO_VARIADIC_TARGS(n))> : \
  151. conditional< \
  152. is_same<T, typename remove_reference<T>::type>::value \
  153. BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME(n), \
  154. typename conditional< \
  155. is_same<T, typename add_const<T>::type>::value, \
  156. no_set_value_free, \
  157. traits::set_value_free< \
  158. typename add_const<T>::type, \
  159. void(BOOST_ASIO_VARIADIC_TARGS(n))> \
  160. >::type, \
  161. traits::set_value_free< \
  162. typename remove_reference<T>::type, \
  163. void(BOOST_ASIO_VARIADIC_DECAY(n))> \
  164. >::type \
  165. { \
  166. }; \
  167. /**/
  168. BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_TRAIT_DEF)
  169. #undef BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_TRAIT_DEF
  170. #undef BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME
  171. #undef BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_1
  172. #undef BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_2
  173. #undef BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_3
  174. #undef BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_4
  175. #undef BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_5
  176. #undef BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_6
  177. #undef BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_7
  178. #undef BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_8
  179. #endif // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
  180. #endif // defined(BOOST_ASIO_HAS_DEDUCED_SET_VALUE_FREE_TRAIT)
  181. } // namespace detail
  182. namespace traits {
  183. template <typename T, typename Vs, typename>
  184. struct set_value_free_default :
  185. detail::set_value_free_trait<T, Vs>
  186. {
  187. };
  188. template <typename T, typename Vs, typename>
  189. struct set_value_free :
  190. set_value_free_default<T, Vs>
  191. {
  192. };
  193. } // namespace traits
  194. } // namespace asio
  195. } // namespace boost
  196. #include <boost/asio/detail/pop_options.hpp>
  197. #endif // BOOST_ASIO_TRAITS_SET_VALUE_FREE_HPP