]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/json/value_to.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / json / value_to.hpp
1 //
2 // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
3 // Copyright (c) 2020 Krystian Stasiowski (sdkrystian@gmail.com)
4 //
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)
7 //
8 // Official repository: https://github.com/boostorg/json
9 //
10
11 #ifndef BOOST_JSON_VALUE_TO_HPP
12 #define BOOST_JSON_VALUE_TO_HPP
13
14 #include <boost/json/detail/config.hpp>
15 #include <boost/json/value.hpp>
16 #include <boost/json/detail/value_to.hpp>
17
18 BOOST_JSON_NS_BEGIN
19
20 /** Customization point tag type.
21
22 This tag type is used by the function
23 @ref value_to to select overloads
24 of `tag_invoke`.
25
26 @note This type is empty; it has no members.
27
28 @see @ref value_from, @ref value_from_tag, @ref value_to,
29 <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1895r0.pdf">
30 tag_invoke: A general pattern for supporting customisable functions</a>
31 */
32 template<class T>
33 struct value_to_tag;
34
35 /** Convert a @ref value to an object of type `T`.
36
37 This function attempts to convert a @ref value
38 to `T` using
39
40 @li one of @ref value's accessors, or
41
42 @li a library-provided generic conversion, or
43
44 @li a user-provided overload of `tag_invoke`.
45
46 In all cases, the conversion is done by calling
47 an overload of `tag_invoke` found by argument-dependent
48 lookup. Its signature should be similar to:
49
50 @code
51 T tag_invoke( value_to_tag<T>, value );
52 @endcode
53
54 The object returned by the function call is
55 returned by @ref value_to as the result of the
56 conversion.
57
58 @par Constraints
59 @code
60 ! std::is_reference< T >::value
61 @endcode
62
63 @par Exception Safety
64 Strong guarantee.
65
66 @tparam T The type to convert to.
67
68 @returns `jv` converted to `T`.
69
70 @param jv The @ref value to convert.
71
72 @see @ref value_to_tag, @ref value_from,
73 <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1895r0.pdf">
74 tag_invoke: A general pattern for supporting customisable functions</a>
75 */
76 template<class T>
77 T
78 value_to(const value& jv)
79 {
80 BOOST_STATIC_ASSERT(! std::is_reference<T>::value);
81 return detail::value_to_impl(
82 value_to_tag<typename std::remove_cv<T>::type>(), jv);
83 }
84
85 /** Convert a @ref value to an object of type `T`.
86
87 This overload is **deleted** and participates in overload resolution only
88 when `U` is not @ref value. The overload exists to prevent unintented
89 creation of temporary @ref value instances, e.g.
90
91 @code
92 auto flag = value_to<bool>(true);
93 @endcode
94 */
95 template<class T, class U
96 #ifndef BOOST_JSON_DOCS
97 , class = typename std::enable_if<!std::is_same<U, value>::value>::type
98 #endif
99 >
100 T
101 value_to(U const& jv) = delete;
102
103 /** Determine a @ref value can be converted to `T`.
104
105 If @ref value can be converted to `T` via a
106 call to @ref value_to, the static data member `value`
107 is defined as `true`. Otherwise, `value` is
108 defined as `false`.
109
110 @see @ref value_to
111 */
112 #ifdef BOOST_JSON_DOCS
113 template<class T>
114 using has_value_to = __see_below__;
115 #else
116 template<class T, class>
117 struct has_value_to
118 : std::false_type { };
119
120 template<class T>
121 struct has_value_to<T, detail::void_t<decltype(
122 detail::value_to_impl(
123 value_to_tag<detail::remove_cvref<T>>(),
124 std::declval<const value&>())),
125 typename std::enable_if<
126 ! std::is_reference<T>::value>::type
127 > > : std::true_type { };
128 #endif
129
130 BOOST_JSON_NS_END
131
132 #endif