100.00% Lines (18/18)
100.00% Functions (9/9)
| TLA | Baseline | Branch | ||||||
|---|---|---|---|---|---|---|---|---|
| Line | Hits | Code | Line | Hits | Code | |||
| 1 | // | 1 | // | |||||
| 2 | // Copyright (c) 2020 Krystian Stasiowski (sdkrystian@gmail.com) | 2 | // Copyright (c) 2020 Krystian Stasiowski (sdkrystian@gmail.com) | |||||
| 3 | // Copyright (c) 2022 Dmitry Arkhipov (grisumbras@yandex.ru) | 3 | // Copyright (c) 2022 Dmitry Arkhipov (grisumbras@yandex.ru) | |||||
| 4 | // | 4 | // | |||||
| 5 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | 5 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | |||||
| 6 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | 6 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |||||
| 7 | // | 7 | // | |||||
| 8 | // Official repository: https://github.com/boostorg/json | 8 | // Official repository: https://github.com/boostorg/json | |||||
| 9 | // | 9 | // | |||||
| 10 | 10 | |||||||
| 11 | #ifndef BOOST_JSON_IMPL_CONVERSION_HPP | 11 | #ifndef BOOST_JSON_IMPL_CONVERSION_HPP | |||||
| 12 | #define BOOST_JSON_IMPL_CONVERSION_HPP | 12 | #define BOOST_JSON_IMPL_CONVERSION_HPP | |||||
| 13 | 13 | |||||||
| 14 | #include <boost/json/fwd.hpp> | 14 | #include <boost/json/fwd.hpp> | |||||
| 15 | #include <boost/json/string_view.hpp> | 15 | #include <boost/json/string_view.hpp> | |||||
| 16 | #include <boost/describe/enumerators.hpp> | 16 | #include <boost/describe/enumerators.hpp> | |||||
| 17 | #include <boost/describe/members.hpp> | 17 | #include <boost/describe/members.hpp> | |||||
| 18 | #include <boost/describe/bases.hpp> | 18 | #include <boost/describe/bases.hpp> | |||||
| 19 | #include <boost/mp11/algorithm.hpp> | 19 | #include <boost/mp11/algorithm.hpp> | |||||
| 20 | #include <boost/mp11/utility.hpp> | 20 | #include <boost/mp11/utility.hpp> | |||||
| 21 | #include <boost/system/result.hpp> | 21 | #include <boost/system/result.hpp> | |||||
| 22 | 22 | |||||||
| 23 | #include <iterator> | 23 | #include <iterator> | |||||
| 24 | #include <tuple> | 24 | #include <tuple> | |||||
| 25 | #include <utility> | 25 | #include <utility> | |||||
| 26 | #ifndef BOOST_NO_CXX17_HDR_VARIANT | 26 | #ifndef BOOST_NO_CXX17_HDR_VARIANT | |||||
| 27 | # include <variant> | 27 | # include <variant> | |||||
| 28 | #endif // BOOST_NO_CXX17_HDR_VARIANT | 28 | #endif // BOOST_NO_CXX17_HDR_VARIANT | |||||
| 29 | 29 | |||||||
| 30 | namespace boost { | 30 | namespace boost { | |||||
| 31 | namespace json { | 31 | namespace json { | |||||
| 32 | 32 | |||||||
| 33 | class value_ref; | 33 | class value_ref; | |||||
| 34 | 34 | |||||||
| 35 | namespace detail { | 35 | namespace detail { | |||||
| 36 | 36 | |||||||
| 37 | #ifdef __cpp_lib_nonmember_container_access | 37 | #ifdef __cpp_lib_nonmember_container_access | |||||
| 38 | using std::size; | 38 | using std::size; | |||||
| 39 | #endif | 39 | #endif | |||||
| 40 | 40 | |||||||
| 41 | template<std::size_t I, class T> | 41 | template<std::size_t I, class T> | |||||
| 42 | using tuple_element_t = typename std::tuple_element<I, T>::type; | 42 | using tuple_element_t = typename std::tuple_element<I, T>::type; | |||||
| 43 | 43 | |||||||
| 44 | template<class T> | 44 | template<class T> | |||||
| 45 | using iterator_type = decltype(std::begin(std::declval<T&>())); | 45 | using iterator_type = decltype(std::begin(std::declval<T&>())); | |||||
| 46 | template<class T> | 46 | template<class T> | |||||
| 47 | using iterator_traits = std::iterator_traits< iterator_type<T> >; | 47 | using iterator_traits = std::iterator_traits< iterator_type<T> >; | |||||
| 48 | 48 | |||||||
| 49 | template<class T> | 49 | template<class T> | |||||
| 50 | using value_type = typename iterator_traits<T>::value_type; | 50 | using value_type = typename iterator_traits<T>::value_type; | |||||
| 51 | template<class T> | 51 | template<class T> | |||||
| 52 | using mapped_type = tuple_element_t< 1, value_type<T> >; | 52 | using mapped_type = tuple_element_t< 1, value_type<T> >; | |||||
| 53 | 53 | |||||||
| 54 | // had to make the metafunction always succeeding in order to make it work | 54 | // had to make the metafunction always succeeding in order to make it work | |||||
| 55 | // with msvc 14.0 | 55 | // with msvc 14.0 | |||||
| 56 | template<class T> | 56 | template<class T> | |||||
| 57 | using key_type_helper = tuple_element_t< 0, value_type<T> >; | 57 | using key_type_helper = tuple_element_t< 0, value_type<T> >; | |||||
| 58 | template<class T> | 58 | template<class T> | |||||
| 59 | using key_type = mp11::mp_eval_or< | 59 | using key_type = mp11::mp_eval_or< | |||||
| 60 | void, | 60 | void, | |||||
| 61 | key_type_helper, | 61 | key_type_helper, | |||||
| 62 | T>; | 62 | T>; | |||||
| 63 | 63 | |||||||
| 64 | template<class T> | 64 | template<class T> | |||||
| 65 | using are_begin_and_end_same = std::is_same< | 65 | using are_begin_and_end_same = std::is_same< | |||||
| 66 | iterator_type<T>, | 66 | iterator_type<T>, | |||||
| 67 | decltype(std::end(std::declval<T&>()))>; | 67 | decltype(std::end(std::declval<T&>()))>; | |||||
| 68 | 68 | |||||||
| 69 | // msvc 14.0 gets confused when std::is_same is used directly | 69 | // msvc 14.0 gets confused when std::is_same is used directly | |||||
| 70 | template<class A, class B> | 70 | template<class A, class B> | |||||
| 71 | using is_same_msvc_140 = std::is_same<A, B>; | 71 | using is_same_msvc_140 = std::is_same<A, B>; | |||||
| 72 | template<class T> | 72 | template<class T> | |||||
| 73 | using is_its_own_value = is_same_msvc_140<value_type<T>, T>; | 73 | using is_its_own_value = is_same_msvc_140<value_type<T>, T>; | |||||
| 74 | 74 | |||||||
| 75 | template<class T> | 75 | template<class T> | |||||
| 76 | using not_its_own_value = mp11::mp_not< is_its_own_value<T> >; | 76 | using not_its_own_value = mp11::mp_not< is_its_own_value<T> >; | |||||
| 77 | 77 | |||||||
| 78 | template<class T> | 78 | template<class T> | |||||
| 79 | using begin_iterator_category = typename std::iterator_traits< | 79 | using begin_iterator_category = typename std::iterator_traits< | |||||
| 80 | iterator_type<T>>::iterator_category; | 80 | iterator_type<T>>::iterator_category; | |||||
| 81 | 81 | |||||||
| 82 | template<class T> | 82 | template<class T> | |||||
| 83 | using has_positive_tuple_size = mp11::mp_bool< | 83 | using has_positive_tuple_size = mp11::mp_bool< | |||||
| 84 | (std::tuple_size<T>::value > 0) >; | 84 | (std::tuple_size<T>::value > 0) >; | |||||
| 85 | 85 | |||||||
| 86 | template<class T> | 86 | template<class T> | |||||
| 87 | using has_unique_keys = has_positive_tuple_size<decltype( | 87 | using has_unique_keys = has_positive_tuple_size<decltype( | |||||
| 88 | std::declval<T&>().emplace( | 88 | std::declval<T&>().emplace( | |||||
| 89 | std::declval<value_type<T>>()))>; | 89 | std::declval<value_type<T>>()))>; | |||||
| 90 | 90 | |||||||
| 91 | template<class T> | 91 | template<class T> | |||||
| 92 | using has_string_type = std::is_same< | 92 | using has_string_type = std::is_same< | |||||
| 93 | typename T::string_type, std::basic_string<typename T::value_type> >; | 93 | typename T::string_type, std::basic_string<typename T::value_type> >; | |||||
| 94 | 94 | |||||||
| 95 | template<class T> | 95 | template<class T> | |||||
| 96 | struct is_value_type_pair_helper : std::false_type | 96 | struct is_value_type_pair_helper : std::false_type | |||||
| 97 | { }; | 97 | { }; | |||||
| 98 | template<class T1, class T2> | 98 | template<class T1, class T2> | |||||
| 99 | struct is_value_type_pair_helper<std::pair<T1, T2>> : std::true_type | 99 | struct is_value_type_pair_helper<std::pair<T1, T2>> : std::true_type | |||||
| 100 | { }; | 100 | { }; | |||||
| 101 | template<class T> | 101 | template<class T> | |||||
| 102 | using is_value_type_pair = is_value_type_pair_helper<value_type<T>>; | 102 | using is_value_type_pair = is_value_type_pair_helper<value_type<T>>; | |||||
| 103 | 103 | |||||||
| 104 | template<class T> | 104 | template<class T> | |||||
| 105 | using has_size_member_helper | 105 | using has_size_member_helper | |||||
| 106 | = std::is_convertible<decltype(std::declval<T&>().size()), std::size_t>; | 106 | = std::is_convertible<decltype(std::declval<T&>().size()), std::size_t>; | |||||
| 107 | template<class T> | 107 | template<class T> | |||||
| 108 | using has_size_member = mp11::mp_valid_and_true<has_size_member_helper, T>; | 108 | using has_size_member = mp11::mp_valid_and_true<has_size_member_helper, T>; | |||||
| 109 | template<class T> | 109 | template<class T> | |||||
| 110 | using has_free_size_helper | 110 | using has_free_size_helper | |||||
| 111 | = std::is_convertible< | 111 | = std::is_convertible< | |||||
| 112 | decltype(size(std::declval<T const&>())), | 112 | decltype(size(std::declval<T const&>())), | |||||
| 113 | std::size_t>; | 113 | std::size_t>; | |||||
| 114 | template<class T> | 114 | template<class T> | |||||
| 115 | using has_free_size = mp11::mp_valid_and_true<has_free_size_helper, T>; | 115 | using has_free_size = mp11::mp_valid_and_true<has_free_size_helper, T>; | |||||
| 116 | template<class T> | 116 | template<class T> | |||||
| 117 | using size_implementation = mp11::mp_cond< | 117 | using size_implementation = mp11::mp_cond< | |||||
| 118 | has_size_member<T>, mp11::mp_int<3>, | 118 | has_size_member<T>, mp11::mp_int<3>, | |||||
| 119 | has_free_size<T>, mp11::mp_int<2>, | 119 | has_free_size<T>, mp11::mp_int<2>, | |||||
| 120 | std::is_array<T>, mp11::mp_int<1>, | 120 | std::is_array<T>, mp11::mp_int<1>, | |||||
| 121 | mp11::mp_true, mp11::mp_int<0>>; | 121 | mp11::mp_true, mp11::mp_int<0>>; | |||||
| 122 | 122 | |||||||
| 123 | template<class T> | 123 | template<class T> | |||||
| 124 | std::size_t | 124 | std::size_t | |||||
| HITCBC | 125 | 141 | try_size(T&& cont, mp11::mp_int<3>) | 125 | 141 | try_size(T&& cont, mp11::mp_int<3>) | ||
| 126 | { | 126 | { | |||||
| HITCBC | 127 | 141 | return cont.size(); | 127 | 141 | return cont.size(); | ||
| 128 | } | 128 | } | |||||
| 129 | 129 | |||||||
| 130 | template<class T> | 130 | template<class T> | |||||
| 131 | std::size_t | 131 | std::size_t | |||||
| HITCBC | 132 | 1 | try_size(T& cont, mp11::mp_int<2>) | 132 | 1 | try_size(T& cont, mp11::mp_int<2>) | ||
| 133 | { | 133 | { | |||||
| HITCBC | 134 | 1 | return size(cont); | 134 | 1 | return size(cont); | ||
| 135 | } | 135 | } | |||||
| 136 | 136 | |||||||
| 137 | template<class T, std::size_t N> | 137 | template<class T, std::size_t N> | |||||
| 138 | std::size_t | 138 | std::size_t | |||||
| HITCBC | 139 | 1 | try_size(T(&)[N], mp11::mp_int<1>) | 139 | 1 | try_size(T(&)[N], mp11::mp_int<1>) | ||
| 140 | { | 140 | { | |||||
| HITCBC | 141 | 1 | return N; | 141 | 1 | return N; | ||
| 142 | } | 142 | } | |||||
| 143 | 143 | |||||||
| 144 | template<class T> | 144 | template<class T> | |||||
| 145 | std::size_t | 145 | std::size_t | |||||
| HITCBC | 146 | 7 | try_size(T&, mp11::mp_int<0>) | 146 | 7 | try_size(T&, mp11::mp_int<0>) | ||
| 147 | { | 147 | { | |||||
| HITCBC | 148 | 7 | return 0; | 148 | 7 | return 0; | ||
| 149 | } | 149 | } | |||||
| 150 | 150 | |||||||
| 151 | template<class T> | 151 | template<class T> | |||||
| 152 | using has_push_back_helper | 152 | using has_push_back_helper | |||||
| 153 | = decltype(std::declval<T&>().push_back(std::declval<value_type<T>>())); | 153 | = decltype(std::declval<T&>().push_back(std::declval<value_type<T>>())); | |||||
| 154 | template<class T> | 154 | template<class T> | |||||
| 155 | using has_push_back = mp11::mp_valid<has_push_back_helper, T>; | 155 | using has_push_back = mp11::mp_valid<has_push_back_helper, T>; | |||||
| 156 | template<class T> | 156 | template<class T> | |||||
| 157 | using inserter_implementation = mp11::mp_cond< | 157 | using inserter_implementation = mp11::mp_cond< | |||||
| 158 | is_tuple_like<T>, mp11::mp_int<2>, | 158 | is_tuple_like<T>, mp11::mp_int<2>, | |||||
| 159 | has_push_back<T>, mp11::mp_int<1>, | 159 | has_push_back<T>, mp11::mp_int<1>, | |||||
| 160 | mp11::mp_true, mp11::mp_int<0>>; | 160 | mp11::mp_true, mp11::mp_int<0>>; | |||||
| 161 | 161 | |||||||
| 162 | template<class T> | 162 | template<class T> | |||||
| 163 | iterator_type<T> | 163 | iterator_type<T> | |||||
| HITCBC | 164 | 56 | inserter( | 164 | 56 | inserter( | ||
| 165 | T& target, | 165 | T& target, | |||||
| 166 | mp11::mp_int<2>) | 166 | mp11::mp_int<2>) | |||||
| 167 | { | 167 | { | |||||
| HITCBC | 168 | 56 | return target.begin(); | 168 | 56 | return target.begin(); | ||
| 169 | } | 169 | } | |||||
| 170 | 170 | |||||||
| 171 | template<class T> | 171 | template<class T> | |||||
| 172 | std::back_insert_iterator<T> | 172 | std::back_insert_iterator<T> | |||||
| HITCBC | 173 | 569 | inserter( | 173 | 569 | inserter( | ||
| 174 | T& target, | 174 | T& target, | |||||
| 175 | mp11::mp_int<1>) | 175 | mp11::mp_int<1>) | |||||
| 176 | { | 176 | { | |||||
| HITCBC | 177 | 569 | return std::back_inserter(target); | 177 | 569 | return std::back_inserter(target); | ||
| 178 | } | 178 | } | |||||
| 179 | 179 | |||||||
| 180 | template<class T> | 180 | template<class T> | |||||
| 181 | std::insert_iterator<T> | 181 | std::insert_iterator<T> | |||||
| HITCBC | 182 | 62 | inserter( | 182 | 62 | inserter( | ||
| 183 | T& target, | 183 | T& target, | |||||
| 184 | mp11::mp_int<0>) | 184 | mp11::mp_int<0>) | |||||
| 185 | { | 185 | { | |||||
| HITCBC | 186 | 62 | return std::inserter( target, target.end() ); | 186 | 62 | return std::inserter( target, target.end() ); | ||
| 187 | } | 187 | } | |||||
| 188 | 188 | |||||||
| 189 | using value_from_conversion = mp11::mp_true; | 189 | using value_from_conversion = mp11::mp_true; | |||||
| 190 | using value_to_conversion = mp11::mp_false; | 190 | using value_to_conversion = mp11::mp_false; | |||||
| 191 | 191 | |||||||
| 192 | - | struct user_conversion_tag { }; | 192 | + | using user_category = std::integral_constant< | |||
| 193 | - | struct context_conversion_tag : user_conversion_tag { }; | 193 | + | conversion_category, conversion_category::user>; | |||
| 194 | - | struct full_context_conversion_tag : context_conversion_tag { }; | 194 | + | using user_context_category = std::integral_constant< | |||
| 195 | - | struct native_conversion_tag { }; | 195 | + | conversion_category, conversion_category::user_context>; | |||
| 196 | - | struct value_conversion_tag : native_conversion_tag { }; | 196 | + | using user_full_context_category = std::integral_constant< | |||
| 197 | - | struct object_conversion_tag : native_conversion_tag { }; | 197 | + | conversion_category, conversion_category::user_full_context>; | |||
| 198 | - | struct array_conversion_tag : native_conversion_tag { }; | 198 | + | using json_value_category = std::integral_constant< | |||
| 199 | - | struct string_conversion_tag : native_conversion_tag { }; | 199 | + | conversion_category, conversion_category::json_value>; | |||
| 200 | - | struct bool_conversion_tag : native_conversion_tag { }; | 200 | + | using json_object_category = std::integral_constant< | |||
| 201 | - | struct value_ref_tag : native_conversion_tag { }; | 201 | + | conversion_category, conversion_category::json_object>; | |||
| 202 | - | struct number_conversion_tag : native_conversion_tag { }; | 202 | + | using json_array_category = std::integral_constant< | |||
| 203 | - | struct integral_conversion_tag : number_conversion_tag { }; | 203 | + | conversion_category, conversion_category::json_array>; | |||
| 204 | - | struct floating_point_conversion_tag : number_conversion_tag { }; | 204 | + | using json_string_category = std::integral_constant< | |||
| 205 | - | struct null_like_conversion_tag { }; | 205 | + | conversion_category, conversion_category::json_string>; | |||
| 206 | - | struct string_like_conversion_tag { }; | 206 | + | using json_value_ref_category = std::integral_constant< | |||
| 207 | - | struct map_like_conversion_tag { }; | 207 | + | conversion_category, conversion_category::json_value_ref>; | |||
| 208 | - | struct path_conversion_tag { }; | 208 | + | ||||
| 209 | - | struct sequence_conversion_tag { }; | 209 | + | template< class Cat > | |||
| 210 | - | struct tuple_conversion_tag { }; | 210 | + | using is_user_conversion = mp11::mp_bool< | |||
| 211 | - | struct described_class_conversion_tag { }; | 211 | + | Cat::value == conversion_category::user | |||
| 212 | - | struct described_enum_conversion_tag { }; | 212 | + | || Cat::value == conversion_category::user_context | |||
| 213 | - | struct variant_conversion_tag { }; | 213 | + | || Cat::value == conversion_category::user_full_context>; | |||
| 214 | - | struct optional_conversion_tag { }; | 214 | + | ||||
| 215 | - | struct no_conversion_tag { }; | 215 | + | template< class Cat > | |||
| 216 | + | using is_native_conversion = mp11::mp_bool< | ||||||
| 217 | + | Cat::value == conversion_category::user | ||||||
| 218 | + | || Cat::value == conversion_category::json_value | ||||||
| 219 | + | || Cat::value == conversion_category::json_object | ||||||
| 220 | + | || Cat::value == conversion_category::json_array | ||||||
| 221 | + | || Cat::value == conversion_category::json_string | ||||||
| 222 | + | || Cat::value == conversion_category::json_value_ref | ||||||
| 223 | + | || Cat::value == conversion_category::boolean | ||||||
| 224 | + | || Cat::value == conversion_category::integer | ||||||
| 225 | + | || Cat::value == conversion_category::floating_point>; | ||||||
| 216 | 226 | |||||||
| 217 | template<class... Args> | 227 | template<class... Args> | |||||
| 218 | using supports_tag_invoke = decltype(tag_invoke( std::declval<Args>()... )); | 228 | using supports_tag_invoke = decltype(tag_invoke( std::declval<Args>()... )); | |||||
| 219 | 229 | |||||||
| 220 | template<class T> | 230 | template<class T> | |||||
| 221 | using has_user_conversion_from_impl = supports_tag_invoke< | 231 | using has_user_conversion_from_impl = supports_tag_invoke< | |||||
| 222 | value_from_tag, value&, T&& >; | 232 | value_from_tag, value&, T&& >; | |||||
| 223 | template<class T> | 233 | template<class T> | |||||
| 224 | using has_user_conversion_to_impl = supports_tag_invoke< | 234 | using has_user_conversion_to_impl = supports_tag_invoke< | |||||
| 225 | value_to_tag<T>, value const& >; | 235 | value_to_tag<T>, value const& >; | |||||
| 226 | template<class T> | 236 | template<class T> | |||||
| 227 | using has_nonthrowing_user_conversion_to_impl = supports_tag_invoke< | 237 | using has_nonthrowing_user_conversion_to_impl = supports_tag_invoke< | |||||
| 228 | try_value_to_tag<T>, value const& >; | 238 | try_value_to_tag<T>, value const& >; | |||||
| 229 | template< class T, class Dir > | 239 | template< class T, class Dir > | |||||
| 230 | using has_user_conversion1 = mp11::mp_if< | 240 | using has_user_conversion1 = mp11::mp_if< | |||||
| 231 | std::is_same<Dir, value_from_conversion>, | 241 | std::is_same<Dir, value_from_conversion>, | |||||
| 232 | mp11::mp_valid<has_user_conversion_from_impl, T>, | 242 | mp11::mp_valid<has_user_conversion_from_impl, T>, | |||||
| 233 | mp11::mp_or< | 243 | mp11::mp_or< | |||||
| 234 | mp11::mp_valid<has_user_conversion_to_impl, T>, | 244 | mp11::mp_valid<has_user_conversion_to_impl, T>, | |||||
| 235 | mp11::mp_valid<has_nonthrowing_user_conversion_to_impl, T>>>; | 245 | mp11::mp_valid<has_nonthrowing_user_conversion_to_impl, T>>>; | |||||
| 236 | 246 | |||||||
| 237 | template< class Ctx, class T > | 247 | template< class Ctx, class T > | |||||
| 238 | using has_context_conversion_from_impl = supports_tag_invoke< | 248 | using has_context_conversion_from_impl = supports_tag_invoke< | |||||
| 239 | value_from_tag, value&, T&&, Ctx const& >; | 249 | value_from_tag, value&, T&&, Ctx const& >; | |||||
| 240 | template< class Ctx, class T > | 250 | template< class Ctx, class T > | |||||
| 241 | using has_context_conversion_to_impl = supports_tag_invoke< | 251 | using has_context_conversion_to_impl = supports_tag_invoke< | |||||
| 242 | value_to_tag<T>, value const&, Ctx const& >; | 252 | value_to_tag<T>, value const&, Ctx const& >; | |||||
| 243 | template< class Ctx, class T > | 253 | template< class Ctx, class T > | |||||
| 244 | using has_nonthrowing_context_conversion_to_impl = supports_tag_invoke< | 254 | using has_nonthrowing_context_conversion_to_impl = supports_tag_invoke< | |||||
| 245 | try_value_to_tag<T>, value const&, Ctx const& >; | 255 | try_value_to_tag<T>, value const&, Ctx const& >; | |||||
| 246 | template< class Ctx, class T, class Dir > | 256 | template< class Ctx, class T, class Dir > | |||||
| 247 | using has_user_conversion2 = mp11::mp_if< | 257 | using has_user_conversion2 = mp11::mp_if< | |||||
| 248 | std::is_same<Dir, value_from_conversion>, | 258 | std::is_same<Dir, value_from_conversion>, | |||||
| 249 | mp11::mp_valid<has_context_conversion_from_impl, Ctx, T>, | 259 | mp11::mp_valid<has_context_conversion_from_impl, Ctx, T>, | |||||
| 250 | mp11::mp_or< | 260 | mp11::mp_or< | |||||
| 251 | mp11::mp_valid<has_context_conversion_to_impl, Ctx, T>, | 261 | mp11::mp_valid<has_context_conversion_to_impl, Ctx, T>, | |||||
| 252 | mp11::mp_valid<has_nonthrowing_context_conversion_to_impl, Ctx, T>>>; | 262 | mp11::mp_valid<has_nonthrowing_context_conversion_to_impl, Ctx, T>>>; | |||||
| 253 | 263 | |||||||
| 254 | template< class Ctx, class T > | 264 | template< class Ctx, class T > | |||||
| 255 | using has_full_context_conversion_from_impl = supports_tag_invoke< | 265 | using has_full_context_conversion_from_impl = supports_tag_invoke< | |||||
| 256 | value_from_tag, value&, T&&, Ctx const&, Ctx const& >; | 266 | value_from_tag, value&, T&&, Ctx const&, Ctx const& >; | |||||
| 257 | template< class Ctx, class T > | 267 | template< class Ctx, class T > | |||||
| 258 | using has_full_context_conversion_to_impl = supports_tag_invoke< | 268 | using has_full_context_conversion_to_impl = supports_tag_invoke< | |||||
| 259 | value_to_tag<T>, value const&, Ctx const&, Ctx const& >; | 269 | value_to_tag<T>, value const&, Ctx const&, Ctx const& >; | |||||
| 260 | template< class Ctx, class T > | 270 | template< class Ctx, class T > | |||||
| 261 | using has_nonthrowing_full_context_conversion_to_impl = supports_tag_invoke< | 271 | using has_nonthrowing_full_context_conversion_to_impl = supports_tag_invoke< | |||||
| 262 | try_value_to_tag<T>, value const&, Ctx const&, Ctx const& >; | 272 | try_value_to_tag<T>, value const&, Ctx const&, Ctx const& >; | |||||
| 263 | template< class Ctx, class T, class Dir > | 273 | template< class Ctx, class T, class Dir > | |||||
| 264 | using has_user_conversion3 = mp11::mp_if< | 274 | using has_user_conversion3 = mp11::mp_if< | |||||
| 265 | std::is_same<Dir, value_from_conversion>, | 275 | std::is_same<Dir, value_from_conversion>, | |||||
| 266 | mp11::mp_valid<has_full_context_conversion_from_impl, Ctx, T>, | 276 | mp11::mp_valid<has_full_context_conversion_from_impl, Ctx, T>, | |||||
| 267 | mp11::mp_or< | 277 | mp11::mp_or< | |||||
| 268 | mp11::mp_valid<has_full_context_conversion_to_impl, Ctx, T>, | 278 | mp11::mp_valid<has_full_context_conversion_to_impl, Ctx, T>, | |||||
| 269 | mp11::mp_valid< | 279 | mp11::mp_valid< | |||||
| 270 | has_nonthrowing_full_context_conversion_to_impl, Ctx, T>>>; | 280 | has_nonthrowing_full_context_conversion_to_impl, Ctx, T>>>; | |||||
| 271 | 281 | |||||||
| 272 | template< class T > | 282 | template< class T > | |||||
| 273 | using described_non_public_members = describe::describe_members< | 283 | using described_non_public_members = describe::describe_members< | |||||
| 274 | T, | 284 | T, | |||||
| 275 | describe::mod_private | 285 | describe::mod_private | |||||
| 276 | | describe::mod_protected | 286 | | describe::mod_protected | |||||
| 277 | | boost::describe::mod_inherited>; | 287 | | boost::describe::mod_inherited>; | |||||
| 278 | 288 | |||||||
| 279 | #if defined(BOOST_MSVC) && BOOST_MSVC < 1920 | 289 | #if defined(BOOST_MSVC) && BOOST_MSVC < 1920 | |||||
| 280 | 290 | |||||||
| 281 | template< class T > | 291 | template< class T > | |||||
| 282 | struct described_member_t_impl; | 292 | struct described_member_t_impl; | |||||
| 283 | 293 | |||||||
| 284 | template< class T, class C > | 294 | template< class T, class C > | |||||
| 285 | struct described_member_t_impl<T C::*> | 295 | struct described_member_t_impl<T C::*> | |||||
| 286 | { | 296 | { | |||||
| 287 | using type = T; | 297 | using type = T; | |||||
| 288 | }; | 298 | }; | |||||
| 289 | 299 | |||||||
| 290 | template< class T, class D > | 300 | template< class T, class D > | |||||
| 291 | using described_member_t = remove_cvref< | 301 | using described_member_t = remove_cvref< | |||||
| 292 | typename described_member_t_impl< | 302 | typename described_member_t_impl< | |||||
| 293 | remove_cvref<decltype(D::pointer)> >::type>; | 303 | remove_cvref<decltype(D::pointer)> >::type>; | |||||
| 294 | 304 | |||||||
| 295 | #else | 305 | #else | |||||
| 296 | 306 | |||||||
| 297 | template< class T, class D > | 307 | template< class T, class D > | |||||
| 298 | using described_member_t = remove_cvref<decltype( | 308 | using described_member_t = remove_cvref<decltype( | |||||
| 299 | std::declval<T&>().* D::pointer )>; | 309 | std::declval<T&>().* D::pointer )>; | |||||
| 300 | 310 | |||||||
| 301 | #endif | 311 | #endif | |||||
| 302 | 312 | |||||||
| 303 | template< class T > | 313 | template< class T > | |||||
| 304 | using described_members = describe::describe_members< | 314 | using described_members = describe::describe_members< | |||||
| 305 | T, describe::mod_any_access | describe::mod_inherited>; | 315 | T, describe::mod_any_access | describe::mod_inherited>; | |||||
| 306 | 316 | |||||||
| 307 | #ifdef BOOST_DESCRIBE_CXX14 | 317 | #ifdef BOOST_DESCRIBE_CXX14 | |||||
| 308 | 318 | |||||||
| 309 | constexpr | 319 | constexpr | |||||
| 310 | bool | 320 | bool | |||||
| 311 | compare_strings(char const* l, char const* r) | 321 | compare_strings(char const* l, char const* r) | |||||
| 312 | { | 322 | { | |||||
| 313 | #if defined(_MSC_VER) && (_MSC_VER <= 1900) && !defined(__clang__) | 323 | #if defined(_MSC_VER) && (_MSC_VER <= 1900) && !defined(__clang__) | |||||
| 314 | return *l == *r && ( (*l == 0) | compare_strings(l + 1, r + 1) ); | 324 | return *l == *r && ( (*l == 0) | compare_strings(l + 1, r + 1) ); | |||||
| 315 | #else | 325 | #else | |||||
| 316 | do | 326 | do | |||||
| 317 | { | 327 | { | |||||
| 318 | if( *l != *r ) | 328 | if( *l != *r ) | |||||
| 319 | return false; | 329 | return false; | |||||
| 320 | if( *l == 0 ) | 330 | if( *l == 0 ) | |||||
| 321 | return true; | 331 | return true; | |||||
| 322 | ++l; | 332 | ++l; | |||||
| 323 | ++r; | 333 | ++r; | |||||
| 324 | } while(true); | 334 | } while(true); | |||||
| 325 | #endif | 335 | #endif | |||||
| 326 | } | 336 | } | |||||
| 327 | 337 | |||||||
| 328 | template< class L, class R > | 338 | template< class L, class R > | |||||
| 329 | struct equal_member_names | 339 | struct equal_member_names | |||||
| 330 | : mp11::mp_bool< compare_strings(L::name, R::name) > | 340 | : mp11::mp_bool< compare_strings(L::name, R::name) > | |||||
| 331 | {}; | 341 | {}; | |||||
| 332 | 342 | |||||||
| 333 | template< class T > | 343 | template< class T > | |||||
| 334 | using uniquely_named_members = mp11::mp_same< | 344 | using uniquely_named_members = mp11::mp_same< | |||||
| 335 | mp11::mp_unique_if< described_members<T>, equal_member_names >, | 345 | mp11::mp_unique_if< described_members<T>, equal_member_names >, | |||||
| 336 | described_members<T> >; | 346 | described_members<T> >; | |||||
| 337 | 347 | |||||||
| 338 | #else | 348 | #else | |||||
| 339 | 349 | |||||||
| 340 | // we only check this in C++14, but the template should exist nevertheless | 350 | // we only check this in C++14, but the template should exist nevertheless | |||||
| 341 | template< class T > | 351 | template< class T > | |||||
| 342 | using uniquely_named_members = std::true_type; | 352 | using uniquely_named_members = std::true_type; | |||||
| 343 | 353 | |||||||
| 344 | #endif // BOOST_DESCRIBE_CXX14 | 354 | #endif // BOOST_DESCRIBE_CXX14 | |||||
| 345 | 355 | |||||||
| 346 | // user conversion (via tag_invoke) | 356 | // user conversion (via tag_invoke) | |||||
| 347 | template< class Ctx, class T, class Dir > | 357 | template< class Ctx, class T, class Dir > | |||||
| 348 | using user_conversion_category = mp11::mp_cond< | 358 | using user_conversion_category = mp11::mp_cond< | |||||
| 349 | - | has_user_conversion3<Ctx, T, Dir>, full_context_conversion_tag, | 359 | + | has_user_conversion3<Ctx, T, Dir>, user_full_context_category, | |||
| 350 | - | has_user_conversion2<Ctx, T, Dir>, context_conversion_tag, | 360 | + | has_user_conversion2<Ctx, T, Dir>, user_context_category, | |||
| 351 | - | has_user_conversion1<T, Dir>, user_conversion_tag>; | 361 | + | has_user_conversion1<T, Dir>, user_category>; | |||
| 352 | 362 | |||||||
| 353 | // native conversions (constructors and member functions of value) | 363 | // native conversions (constructors and member functions of value) | |||||
| 354 | template< class T > | 364 | template< class T > | |||||
| 355 | using native_conversion_category = mp11::mp_cond< | 365 | using native_conversion_category = mp11::mp_cond< | |||||
| 356 | - | std::is_same<T, value>, value_conversion_tag, | 366 | + | std::is_same<T, value_ref>, json_value_ref_category, | |||
| 357 | - | std::is_same<T, array>, array_conversion_tag, | 367 | + | std::is_same<T, value>, json_value_category, | |||
| 358 | - | std::is_same<T, object>, object_conversion_tag, | 368 | + | std::is_same<T, array>, json_array_category, | |||
| 359 | - | std::is_same<T, string>, string_conversion_tag>; | 369 | + | std::is_same<T, object>, json_object_category, | |||
| 370 | + | std::is_same<T, string>, json_string_category>; | ||||||
| 360 | - | // generic conversions | ||||||
| 361 | 371 | |||||||
| 362 | template< class T > | 372 | template< class T > | |||||
| 363 | - | using generic_conversion_category = mp11::mp_cond< | 373 | + | using conversion_category_t = std::integral_constant< | |||
| 364 | - | // std::is_same<T,std::initializer_list<value_ref>>, init_list_tag, | 374 | + | conversion_category, conversion_category_of<T>::value>; | |||
| 365 | - | std::is_same<T, value_ref>, value_ref_tag, | ||||||
| 366 | - | |||||||
| 367 | - | std::is_same<T, bool>, bool_conversion_tag, | ||||||
| 368 | - | std::is_integral<T>, integral_conversion_tag, | ||||||
| 369 | - | std::is_floating_point<T>, floating_point_conversion_tag, | ||||||
| 370 | - | is_null_like<T>, null_like_conversion_tag, | ||||||
| 371 | - | is_string_like<T>, string_like_conversion_tag, | ||||||
| 372 | - | is_variant_like<T>, variant_conversion_tag, | ||||||
| 373 | - | is_optional_like<T>, optional_conversion_tag, | ||||||
| 374 | - | is_map_like<T>, map_like_conversion_tag, | ||||||
| 375 | - | is_sequence_like<T>, sequence_conversion_tag, | ||||||
| 376 | - | is_tuple_like<T>, tuple_conversion_tag, | ||||||
| 377 | - | is_described_class<T>, described_class_conversion_tag, | ||||||
| 378 | - | is_described_enum<T>, described_enum_conversion_tag, | ||||||
| 379 | - | is_path_like<T>, path_conversion_tag, | ||||||
| 380 | - | // failed to find a suitable implementation | ||||||
| 381 | - | mp11::mp_true, no_conversion_tag>; | ||||||
| 382 | 375 | |||||||
| 383 | template< class T > | 376 | template< class T > | |||||
| 384 | using nested_type = typename T::type; | 377 | using nested_type = typename T::type; | |||||
| 385 | template< class T1, class T2 > | 378 | template< class T1, class T2 > | |||||
| 386 | - | using conversion_category_impl_helper = mp11::mp_eval_if_not< | 379 | + | using extended_conversion_category_impl_helper = mp11::mp_eval_if_not< | |||
| 387 | - | std::is_same<detail::no_conversion_tag, T1>, | 380 | + | std::is_same<unknown_category, T1>, | |||
| 388 | T1, | 381 | T1, | |||||
| 389 | mp11::mp_eval_or_q, T1, mp11::mp_quote<nested_type>, T2>; | 382 | mp11::mp_eval_or_q, T1, mp11::mp_quote<nested_type>, T2>; | |||||
| 390 | template< class Ctx, class T, class Dir > | 383 | template< class Ctx, class T, class Dir > | |||||
| 391 | - | struct conversion_category_impl | 384 | + | struct extended_conversion_category_impl | |||
| 392 | { | 385 | { | |||||
| 393 | using type = mp11::mp_fold< | 386 | using type = mp11::mp_fold< | |||||
| 394 | mp11::mp_list< | 387 | mp11::mp_list< | |||||
| 395 | mp11::mp_defer<user_conversion_category, Ctx, T, Dir>, | 388 | mp11::mp_defer<user_conversion_category, Ctx, T, Dir>, | |||||
| 396 | mp11::mp_defer<native_conversion_category, T>, | 389 | mp11::mp_defer<native_conversion_category, T>, | |||||
| 397 | - | mp11::mp_defer<generic_conversion_category, T>>, | 390 | + | mp11::mp_defer<conversion_category_t, T>>, | |||
| 398 | - | no_conversion_tag, | 391 | + | unknown_category, | |||
| 399 | - | conversion_category_impl_helper>; | 392 | + | extended_conversion_category_impl_helper>; | |||
| 400 | }; | 393 | }; | |||||
| 401 | template< class Ctx, class T, class Dir > | 394 | template< class Ctx, class T, class Dir > | |||||
| 402 | - | using conversion_category = | 395 | + | using extended_conversion_category = | |||
| 403 | - | typename conversion_category_impl< Ctx, T, Dir >::type; | 396 | + | typename extended_conversion_category_impl<Ctx, T, Dir>::type; | |||
| 404 | 397 | |||||||
| 405 | template< class T > | 398 | template< class T > | |||||
| 406 | - | using any_conversion_tag = mp11::mp_not< | 399 | + | using any_conversion_tag = mp11::mp_not< std::is_same<T, unknown_category> >; | |||
| 407 | - | std::is_same< T, no_conversion_tag > >; | ||||||
| 408 | 400 | |||||||
| 409 | template< class T, class Dir, class... Ctxs > | 401 | template< class T, class Dir, class... Ctxs > | |||||
| 410 | - | struct conversion_category_impl< std::tuple<Ctxs...>, T, Dir > | 402 | + | struct extended_conversion_category_impl< std::tuple<Ctxs...>, T, Dir > | |||
| 411 | { | 403 | { | |||||
| 412 | using ctxs = mp11::mp_list< remove_cvref<Ctxs>... >; | 404 | using ctxs = mp11::mp_list< remove_cvref<Ctxs>... >; | |||||
| 413 | using cats = mp11::mp_list< | 405 | using cats = mp11::mp_list< | |||||
| 414 | - | conversion_category<remove_cvref<Ctxs>, T, Dir>... >; | 406 | + | extended_conversion_category<remove_cvref<Ctxs>, T, Dir>... >; | |||
| 415 | 407 | |||||||
| 416 | template< class I > | 408 | template< class I > | |||||
| 417 | using exists = mp11::mp_less< I, mp11::mp_size<cats> >; | 409 | using exists = mp11::mp_less< I, mp11::mp_size<cats> >; | |||||
| 418 | 410 | |||||||
| 419 | - | using context2 = mp11::mp_find< cats, full_context_conversion_tag >; | 411 | + | using context2 = mp11::mp_find< cats, user_full_context_category >; | |||
| 420 | - | using context1 = mp11::mp_find< cats, context_conversion_tag >; | 412 | + | using context1 = mp11::mp_find< cats, user_context_category >; | |||
| 421 | - | using context0 = mp11::mp_find< cats, user_conversion_tag >; | 413 | + | using context0 = mp11::mp_find< cats, user_category >; | |||
| 422 | using index = mp11::mp_cond< | 414 | using index = mp11::mp_cond< | |||||
| 423 | exists<context2>, context2, | 415 | exists<context2>, context2, | |||||
| 424 | exists<context1>, context1, | 416 | exists<context1>, context1, | |||||
| 425 | exists<context0>, context0, | 417 | exists<context0>, context0, | |||||
| 426 | mp11::mp_true, mp11::mp_find_if< cats, any_conversion_tag > >; | 418 | mp11::mp_true, mp11::mp_find_if< cats, any_conversion_tag > >; | |||||
| 427 | using type = mp11::mp_eval_or< | 419 | using type = mp11::mp_eval_or< | |||||
| 428 | - | no_conversion_tag, | 420 | + | unknown_category, | |||
| 429 | mp11::mp_at, cats, index >; | 421 | mp11::mp_at, cats, index >; | |||||
| 430 | }; | 422 | }; | |||||
| 431 | 423 | |||||||
| 432 | struct no_context | 424 | struct no_context | |||||
| 433 | {}; | 425 | {}; | |||||
| 434 | 426 | |||||||
| 435 | template <class T, class Dir> | 427 | template <class T, class Dir> | |||||
| 436 | using can_convert = mp11::mp_not< | 428 | using can_convert = mp11::mp_not< | |||||
| 437 | std::is_same< | 429 | std::is_same< | |||||
| 438 | - | detail::conversion_category<no_context, T, Dir>, | 430 | + | detail::extended_conversion_category<no_context, T, Dir>, | |||
| 439 | - | detail::no_conversion_tag>>; | 431 | + | unknown_category>>; | |||
| 440 | 432 | |||||||
| 441 | template<class Impl1, class Impl2> | 433 | template<class Impl1, class Impl2> | |||||
| 442 | using conversion_round_trips_helper = mp11::mp_or< | 434 | using conversion_round_trips_helper = mp11::mp_or< | |||||
| 443 | std::is_same<Impl1, Impl2>, | 435 | std::is_same<Impl1, Impl2>, | |||||
| 444 | - | std::is_base_of<user_conversion_tag, Impl1>, | 436 | + | is_user_conversion<Impl1>, | |||
| 445 | - | std::is_base_of<user_conversion_tag, Impl2>>; | 437 | + | is_user_conversion<Impl2>>; | |||
| 446 | template< class Ctx, class T, class Dir > | 438 | template< class Ctx, class T, class Dir > | |||||
| 447 | using conversion_round_trips = conversion_round_trips_helper< | 439 | using conversion_round_trips = conversion_round_trips_helper< | |||||
| 448 | - | conversion_category<Ctx, T, Dir>, | 440 | + | extended_conversion_category<Ctx, T, Dir>, | |||
| 449 | - | conversion_category<Ctx, T, mp11::mp_not<Dir>>>; | 441 | + | extended_conversion_category<Ctx, T, mp11::mp_not<Dir>>>; | |||
| 450 | 442 | |||||||
| 451 | template< class T1, class T2 > | 443 | template< class T1, class T2 > | |||||
| 452 | struct copy_cref_helper | 444 | struct copy_cref_helper | |||||
| 453 | { | 445 | { | |||||
| 454 | using type = remove_cvref<T2>; | 446 | using type = remove_cvref<T2>; | |||||
| 455 | }; | 447 | }; | |||||
| 456 | template< class T1, class T2 > | 448 | template< class T1, class T2 > | |||||
| 457 | using copy_cref = typename copy_cref_helper< T1, T2 >::type; | 449 | using copy_cref = typename copy_cref_helper< T1, T2 >::type; | |||||
| 458 | 450 | |||||||
| 459 | template< class T1, class T2 > | 451 | template< class T1, class T2 > | |||||
| 460 | struct copy_cref_helper<T1 const, T2> | 452 | struct copy_cref_helper<T1 const, T2> | |||||
| 461 | { | 453 | { | |||||
| 462 | using type = remove_cvref<T2> const; | 454 | using type = remove_cvref<T2> const; | |||||
| 463 | }; | 455 | }; | |||||
| 464 | template< class T1, class T2 > | 456 | template< class T1, class T2 > | |||||
| 465 | struct copy_cref_helper<T1&, T2> | 457 | struct copy_cref_helper<T1&, T2> | |||||
| 466 | { | 458 | { | |||||
| 467 | using type = copy_cref<T1, T2>&; | 459 | using type = copy_cref<T1, T2>&; | |||||
| 468 | }; | 460 | }; | |||||
| 469 | template< class T1, class T2 > | 461 | template< class T1, class T2 > | |||||
| 470 | struct copy_cref_helper<T1&&, T2> | 462 | struct copy_cref_helper<T1&&, T2> | |||||
| 471 | { | 463 | { | |||||
| 472 | using type = copy_cref<T1, T2>&&; | 464 | using type = copy_cref<T1, T2>&&; | |||||
| 473 | }; | 465 | }; | |||||
| 474 | 466 | |||||||
| 475 | template< class Rng, class Traits > | 467 | template< class Rng, class Traits > | |||||
| 476 | using forwarded_value_helper = mp11::mp_if< | 468 | using forwarded_value_helper = mp11::mp_if< | |||||
| 477 | std::is_convertible< | 469 | std::is_convertible< | |||||
| 478 | typename Traits::reference, | 470 | typename Traits::reference, | |||||
| 479 | copy_cref<Rng, typename Traits::value_type> >, | 471 | copy_cref<Rng, typename Traits::value_type> >, | |||||
| 480 | copy_cref<Rng, typename Traits::value_type>, | 472 | copy_cref<Rng, typename Traits::value_type>, | |||||
| 481 | typename Traits::value_type >; | 473 | typename Traits::value_type >; | |||||
| 482 | 474 | |||||||
| 483 | template< class Rng > | 475 | template< class Rng > | |||||
| 484 | using forwarded_value = forwarded_value_helper< | 476 | using forwarded_value = forwarded_value_helper< | |||||
| 485 | Rng, iterator_traits< Rng > >; | 477 | Rng, iterator_traits< Rng > >; | |||||
| 486 | 478 | |||||||
| 487 | template< class Ctx, class T, class Dir > | 479 | template< class Ctx, class T, class Dir > | |||||
| 488 | struct supported_context | 480 | struct supported_context | |||||
| 489 | { | 481 | { | |||||
| 490 | using type = Ctx; | 482 | using type = Ctx; | |||||
| 491 | 483 | |||||||
| 492 | static | 484 | static | |||||
| 493 | type const& | 485 | type const& | |||||
| HITCBC | 494 | 32 | get( Ctx const& ctx ) noexcept | 486 | 32 | get( Ctx const& ctx ) noexcept | ||
| 495 | { | 487 | { | |||||
| HITCBC | 496 | 32 | return ctx; | 488 | 32 | return ctx; | ||
| 497 | } | 489 | } | |||||
| 498 | }; | 490 | }; | |||||
| 499 | 491 | |||||||
| 500 | template< class T, class Dir, class... Ctxs > | 492 | template< class T, class Dir, class... Ctxs > | |||||
| 501 | struct supported_context< std::tuple<Ctxs...>, T, Dir > | 493 | struct supported_context< std::tuple<Ctxs...>, T, Dir > | |||||
| 502 | { | 494 | { | |||||
| 503 | using Ctx = std::tuple<Ctxs...>; | 495 | using Ctx = std::tuple<Ctxs...>; | |||||
| 504 | - | using impl = conversion_category_impl<Ctx, T, Dir>; | 496 | + | using impl = extended_conversion_category_impl<Ctx, T, Dir>; | |||
| 505 | using index = typename impl::index; | 497 | using index = typename impl::index; | |||||
| 506 | using next_supported = supported_context< | 498 | using next_supported = supported_context< | |||||
| 507 | mp11::mp_at< typename impl::ctxs, index >, T, Dir >; | 499 | mp11::mp_at< typename impl::ctxs, index >, T, Dir >; | |||||
| 508 | using type = typename next_supported::type; | 500 | using type = typename next_supported::type; | |||||
| 509 | 501 | |||||||
| 510 | static | 502 | static | |||||
| 511 | type const& | 503 | type const& | |||||
| HITCBC | 512 | 19 | get( Ctx const& ctx ) noexcept | 504 | 19 | get( Ctx const& ctx ) noexcept | ||
| 513 | { | 505 | { | |||||
| HITCBC | 514 | 19 | return next_supported::get( std::get<index::value>( ctx ) ); | 506 | 19 | return next_supported::get( std::get<index::value>( ctx ) ); | ||
| 515 | } | 507 | } | |||||
| 516 | }; | 508 | }; | |||||
| 517 | 509 | |||||||
| 518 | template< class T > | 510 | template< class T > | |||||
| 519 | using value_result_type = typename std::decay< | 511 | using value_result_type = typename std::decay< | |||||
| 520 | decltype( std::declval<T&>().value() )>::type; | 512 | decltype( std::declval<T&>().value() )>::type; | |||||
| 521 | 513 | |||||||
| 522 | template< class T > | 514 | template< class T > | |||||
| 523 | using can_reset = decltype( std::declval<T&>().reset() ); | 515 | using can_reset = decltype( std::declval<T&>().reset() ); | |||||
| 524 | 516 | |||||||
| 525 | template< class T > | 517 | template< class T > | |||||
| 526 | using has_valueless_by_exception = | 518 | using has_valueless_by_exception = | |||||
| 527 | decltype( std::declval<T const&>().valueless_by_exception() ); | 519 | decltype( std::declval<T const&>().valueless_by_exception() ); | |||||
| 528 | 520 | |||||||
| 529 | } // namespace detail | 521 | } // namespace detail | |||||
| 530 | 522 | |||||||
| 531 | template <class T> | 523 | template <class T> | |||||
| 532 | struct result_for<T, value> | 524 | struct result_for<T, value> | |||||
| 533 | { | 525 | { | |||||
| 534 | using type = system::result< detail::remove_cvref<T> >; | 526 | using type = system::result< detail::remove_cvref<T> >; | |||||
| 535 | }; | 527 | }; | |||||
| 536 | 528 | |||||||
| 537 | template<class T> | 529 | template<class T> | |||||
| 538 | struct is_string_like | 530 | struct is_string_like | |||||
| 539 | : std::is_convertible<T, string_view> | 531 | : std::is_convertible<T, string_view> | |||||
| 540 | { }; | 532 | { }; | |||||
| 541 | 533 | |||||||
| 542 | template<class T> | 534 | template<class T> | |||||
| 543 | struct is_path_like | 535 | struct is_path_like | |||||
| 544 | : mp11::mp_all< | 536 | : mp11::mp_all< | |||||
| 545 | mp11::mp_valid_and_true<detail::is_its_own_value, T>, | 537 | mp11::mp_valid_and_true<detail::is_its_own_value, T>, | |||||
| 546 | mp11::mp_valid_and_true<detail::has_string_type, T>> | 538 | mp11::mp_valid_and_true<detail::has_string_type, T>> | |||||
| 547 | { }; | 539 | { }; | |||||
| 548 | template<class T> | 540 | template<class T> | |||||
| 549 | struct is_sequence_like | 541 | struct is_sequence_like | |||||
| 550 | : mp11::mp_all< | 542 | : mp11::mp_all< | |||||
| 551 | mp11::mp_valid_and_true<detail::are_begin_and_end_same, T>, | 543 | mp11::mp_valid_and_true<detail::are_begin_and_end_same, T>, | |||||
| 552 | mp11::mp_valid_and_true<detail::not_its_own_value, T>, | 544 | mp11::mp_valid_and_true<detail::not_its_own_value, T>, | |||||
| 553 | mp11::mp_valid<detail::begin_iterator_category, T>> | 545 | mp11::mp_valid<detail::begin_iterator_category, T>> | |||||
| 554 | { }; | 546 | { }; | |||||
| 555 | 547 | |||||||
| 556 | template<class T> | 548 | template<class T> | |||||
| 557 | struct is_map_like | 549 | struct is_map_like | |||||
| 558 | : mp11::mp_all< | 550 | : mp11::mp_all< | |||||
| 559 | is_sequence_like<T>, | 551 | is_sequence_like<T>, | |||||
| 560 | mp11::mp_valid_and_true<detail::is_value_type_pair, T>, | 552 | mp11::mp_valid_and_true<detail::is_value_type_pair, T>, | |||||
| 561 | is_string_like<detail::key_type<T>>, | 553 | is_string_like<detail::key_type<T>>, | |||||
| 562 | mp11::mp_valid_and_true<detail::has_unique_keys, T>> | 554 | mp11::mp_valid_and_true<detail::has_unique_keys, T>> | |||||
| 563 | { }; | 555 | { }; | |||||
| 564 | 556 | |||||||
| 565 | template<class T> | 557 | template<class T> | |||||
| 566 | struct is_tuple_like | 558 | struct is_tuple_like | |||||
| 567 | : mp11::mp_valid_and_true<detail::has_positive_tuple_size, T> | 559 | : mp11::mp_valid_and_true<detail::has_positive_tuple_size, T> | |||||
| 568 | { }; | 560 | { }; | |||||
| 569 | 561 | |||||||
| 570 | template<> | 562 | template<> | |||||
| 571 | struct is_null_like<std::nullptr_t> | 563 | struct is_null_like<std::nullptr_t> | |||||
| 572 | : std::true_type | 564 | : std::true_type | |||||
| 573 | { }; | 565 | { }; | |||||
| 574 | 566 | |||||||
| 575 | #ifndef BOOST_NO_CXX17_HDR_VARIANT | 567 | #ifndef BOOST_NO_CXX17_HDR_VARIANT | |||||
| 576 | template<> | 568 | template<> | |||||
| 577 | struct is_null_like<std::monostate> | 569 | struct is_null_like<std::monostate> | |||||
| 578 | : std::true_type | 570 | : std::true_type | |||||
| 579 | { }; | 571 | { }; | |||||
| 580 | #endif // BOOST_NO_CXX17_HDR_VARIANT | 572 | #endif // BOOST_NO_CXX17_HDR_VARIANT | |||||
| 581 | 573 | |||||||
| 582 | template<class T> | 574 | template<class T> | |||||
| 583 | struct is_described_class | 575 | struct is_described_class | |||||
| 584 | : mp11::mp_and< | 576 | : mp11::mp_and< | |||||
| 585 | describe::has_describe_members<T>, | 577 | describe::has_describe_members<T>, | |||||
| 586 | mp11::mp_not< std::is_union<T> >, | 578 | mp11::mp_not< std::is_union<T> >, | |||||
| 587 | mp11::mp_empty< | 579 | mp11::mp_empty< | |||||
| 588 | mp11::mp_eval_or< | 580 | mp11::mp_eval_or< | |||||
| 589 | mp11::mp_list<>, detail::described_non_public_members, T>>> | 581 | mp11::mp_list<>, detail::described_non_public_members, T>>> | |||||
| 590 | { }; | 582 | { }; | |||||
| 591 | 583 | |||||||
| 592 | template<class T> | 584 | template<class T> | |||||
| 593 | struct is_described_enum | 585 | struct is_described_enum | |||||
| 594 | : describe::has_describe_enumerators<T> | 586 | : describe::has_describe_enumerators<T> | |||||
| 595 | { }; | 587 | { }; | |||||
| 596 | 588 | |||||||
| 597 | template<class T> | 589 | template<class T> | |||||
| 598 | struct is_variant_like : mp11::mp_valid<detail::has_valueless_by_exception, T> | 590 | struct is_variant_like : mp11::mp_valid<detail::has_valueless_by_exception, T> | |||||
| 599 | { }; | 591 | { }; | |||||
| 600 | 592 | |||||||
| 601 | template<class T> | 593 | template<class T> | |||||
| 602 | struct is_optional_like | 594 | struct is_optional_like | |||||
| 603 | : mp11::mp_and< | 595 | : mp11::mp_and< | |||||
| 604 | mp11::mp_not<std::is_void< | 596 | mp11::mp_not<std::is_void< | |||||
| 605 | mp11::mp_eval_or<void, detail::value_result_type, T>>>, | 597 | mp11::mp_eval_or<void, detail::value_result_type, T>>>, | |||||
| 606 | mp11::mp_valid<detail::can_reset, T>> | 598 | mp11::mp_valid<detail::can_reset, T>> | |||||
| 607 | { }; | 599 | { }; | |||||
| 608 | 600 | |||||||
| 609 | } // namespace json | 601 | } // namespace json | |||||
| 610 | } // namespace boost | 602 | } // namespace boost | |||||
| 611 | 603 | |||||||
| 612 | #endif // BOOST_JSON_IMPL_CONVERSION_HPP | 604 | #endif // BOOST_JSON_IMPL_CONVERSION_HPP | |||||