1 // 2 // traits/set_value_member.hpp 3 // ~~~~~~~~~~~~~~~~~~~~~~~~~ 4 // 5 // Copyright (c) 2003-2020 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 11 #ifndef BOOST_ASIO_TRAITS_SET_VALUE_MEMBER_HPP 12 #define BOOST_ASIO_TRAITS_SET_VALUE_MEMBER_HPP 13 14 #if defined(_MSC_VER) && (_MSC_VER >= 1200) 15 # pragma once 16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) 17 18 #include <boost/asio/detail/config.hpp> 19 #include <boost/asio/detail/type_traits.hpp> 20 #include <boost/asio/detail/variadic_templates.hpp> 21 22 #if defined(BOOST_ASIO_HAS_DECLTYPE) \ 23 && defined(BOOST_ASIO_HAS_NOEXCEPT) \ 24 && defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE) 25 # define BOOST_ASIO_HAS_DEDUCED_SET_VALUE_MEMBER_TRAIT 1 26 #endif // defined(BOOST_ASIO_HAS_DECLTYPE) 27 // && defined(BOOST_ASIO_HAS_NOEXCEPT) 28 // && defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE) 29 30 #include <boost/asio/detail/push_options.hpp> 31 32 namespace boost { 33 namespace asio { 34 namespace traits { 35 36 template <typename T, typename Vs, typename = void> 37 struct set_value_member_default; 38 39 template <typename T, typename Vs, typename = void> 40 struct set_value_member; 41 42 } // namespace traits 43 namespace detail { 44 45 struct no_set_value_member 46 { 47 BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = false); 48 BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false); 49 }; 50 51 #if defined(BOOST_ASIO_HAS_DEDUCED_SET_VALUE_MEMBER_TRAIT) 52 53 template <typename T, typename Vs, typename = void> 54 struct set_value_member_trait : no_set_value_member 55 { 56 }; 57 58 #if defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES) 59 60 template <typename T, typename... Vs> 61 struct set_value_member_trait<T, void(Vs...), 62 typename void_type< 63 decltype(declval<T>().set_value(declval<Vs>()...)) 64 >::type> 65 { 66 BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true); 67 68 using result_type = decltype( 69 declval<T>().set_value(declval<Vs>()...)); 70 71 BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = noexcept( 72 declval<T>().set_value(declval<Vs>()...))); 73 }; 74 75 #else // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES) 76 77 template <typename T> 78 struct set_value_member_trait<T, void(), 79 typename void_type< 80 decltype(declval<T>().set_value()) 81 >::type> 82 { 83 BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true); 84 85 using result_type = decltype(declval<T>().set_value()); 86 87 BOOST_ASIO_STATIC_CONSTEXPR(bool, 88 is_noexcept = noexcept(declval<T>().set_value())); 89 }; 90 91 #define BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_TRAIT_DEF(n) \ 92 template <typename T, BOOST_ASIO_VARIADIC_TPARAMS(n)> \ 93 struct set_value_member_trait<T, void(BOOST_ASIO_VARIADIC_TARGS(n)), \ 94 typename void_type< \ 95 decltype(declval<T>().set_value(BOOST_ASIO_VARIADIC_DECLVAL(n))) \ 96 >::type> \ 97 { \ 98 BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true); \ 99 \ 100 using result_type = decltype( \ 101 declval<T>().set_value(BOOST_ASIO_VARIADIC_DECLVAL(n))); \ 102 \ 103 BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = noexcept( \ 104 declval<T>().set_value(BOOST_ASIO_VARIADIC_DECLVAL(n)))); \ 105 }; \ 106 /**/ 107 BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_TRAIT_DEF) 108 #undef BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_TRAIT_DEF 109 110 #endif // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES) 111 112 #else // defined(BOOST_ASIO_HAS_DEDUCED_SET_VALUE_MEMBER_TRAIT) 113 114 template <typename T, typename Vs, typename = void> 115 struct set_value_member_trait; 116 117 #if defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES) 118 119 template <typename T, typename... Vs> 120 struct set_value_member_trait<T, void(Vs...)> : 121 conditional< 122 is_same<T, typename remove_reference<T>::type>::value 123 && conjunction<is_same<Vs, typename decay<Vs>::type>...>::value, 124 typename conditional< 125 is_same<T, typename add_const<T>::type>::value, 126 no_set_value_member, 127 traits::set_value_member<typename add_const<T>::type, void(Vs...)> 128 >::type, 129 traits::set_value_member< 130 typename remove_reference<T>::type, 131 void(typename decay<Vs>::type...)> 132 >::type 133 { 134 }; 135 136 #else // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES) 137 138 template <typename T> 139 struct set_value_member_trait<T, void()> : 140 conditional< 141 is_same<T, typename remove_reference<T>::type>::value, 142 typename conditional< 143 is_same<T, typename add_const<T>::type>::value, 144 no_set_value_member, 145 traits::set_value_member<typename add_const<T>::type, void()> 146 >::type, 147 traits::set_value_member<typename remove_reference<T>::type, void()> 148 >::type 149 { 150 }; 151 152 #define BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME(n) \ 153 BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_##n 154 155 #define BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_1 \ 156 && is_same<T1, typename decay<T1>::type>::value 157 #define BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_2 \ 158 BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_1 \ 159 && is_same<T2, typename decay<T2>::type>::value 160 #define BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_3 \ 161 BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_2 \ 162 && is_same<T3, typename decay<T3>::type>::value 163 #define BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_4 \ 164 BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_3 \ 165 && is_same<T4, typename decay<T4>::type>::value 166 #define BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_5 \ 167 BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_4 \ 168 && is_same<T5, typename decay<T5>::type>::value 169 #define BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_6 \ 170 BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_5 \ 171 && is_same<T6, typename decay<T6>::type>::value 172 #define BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_7 \ 173 BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_6 \ 174 && is_same<T7, typename decay<T7>::type>::value 175 #define BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_8 \ 176 BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_7 \ 177 && is_same<T8, typename decay<T8>::type>::value 178 179 #define BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_TRAIT_DEF(n) \ 180 template <typename T, BOOST_ASIO_VARIADIC_TPARAMS(n)> \ 181 struct set_value_member_trait<T, void(BOOST_ASIO_VARIADIC_TARGS(n))> : \ 182 conditional< \ 183 is_same<T, typename remove_reference<T>::type>::value \ 184 BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME(n), \ 185 typename conditional< \ 186 is_same<T, typename add_const<T>::type>::value, \ 187 no_set_value_member, \ 188 traits::set_value_member< \ 189 typename add_const<T>::type, \ 190 void(BOOST_ASIO_VARIADIC_TARGS(n))> \ 191 >::type, \ 192 traits::set_value_member< \ 193 typename remove_reference<T>::type, \ 194 void(BOOST_ASIO_VARIADIC_DECAY(n))> \ 195 >::type \ 196 { \ 197 }; \ 198 /**/ 199 BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_TRAIT_DEF) 200 #undef BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_TRAIT_DEF 201 #undef BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME 202 #undef BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_1 203 #undef BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_2 204 #undef BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_3 205 #undef BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_4 206 #undef BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_5 207 #undef BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_6 208 #undef BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_7 209 #undef BOOST_ASIO_PRIVATE_SET_VALUE_MEMBER_IS_SAME_8 210 211 #endif // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES) 212 213 #endif // defined(BOOST_ASIO_HAS_DEDUCED_SET_VALUE_MEMBER_TRAIT) 214 215 } // namespace detail 216 namespace traits { 217 218 template <typename T, typename Vs, typename> 219 struct set_value_member_default : 220 detail::set_value_member_trait<T, Vs> 221 { 222 }; 223 224 template <typename T, typename Vs, typename> 225 struct set_value_member : 226 set_value_member_default<T, Vs> 227 { 228 }; 229 230 } // namespace traits 231 } // namespace asio 232 } // namespace boost 233 234 #include <boost/asio/detail/pop_options.hpp> 235 236 #endif // BOOST_ASIO_TRAITS_SET_VALUE_MEMBER_HPP 237