]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/beast/http/type_traits.hpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / boost / beast / http / type_traits.hpp
1 //
2 // Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // Official repository: https://github.com/boostorg/beast
8 //
9
10 #ifndef BOOST_BEAST_HTTP_TYPE_TRAITS_HPP
11 #define BOOST_BEAST_HTTP_TYPE_TRAITS_HPP
12
13 #include <boost/beast/core/detail/config.hpp>
14 #include <boost/beast/core/error.hpp>
15 #include <boost/beast/core/string.hpp>
16 #include <boost/beast/core/type_traits.hpp>
17 #include <boost/beast/http/detail/type_traits.hpp>
18 #include <boost/asio/buffer.hpp>
19 #include <boost/optional.hpp>
20 #include <type_traits>
21 #include <utility>
22
23 namespace boost {
24 namespace beast {
25 namespace http {
26
27 template<bool, class, class>
28 struct message;
29
30 /** Determine if `T` meets the requirements of @b Body.
31
32 This metafunction is equivalent to `std::true_type`
33 if `T` has a nested type named `value_type`.
34
35 @tparam T The body type to test.
36
37 @par Example
38 @code
39 template<bool isRequest, class Body, class Fields>
40 void check_body(message<isRequest, Body, Fields> const&)
41 {
42 static_assert(is_body<Body>::value,
43 "Body requirements not met");
44 }
45 @endcode
46 */
47 template<class T>
48 #if BOOST_BEAST_DOXYGEN
49 struct is_body : std::integral_constant<bool, ...>{};
50 #else
51 using is_body = detail::has_value_type<T>;
52 #endif
53
54 /** Determine if a @b Body type has a reader.
55
56 This metafunction is equivalent to `std::true_type` if:
57
58 @li `T` has a nested type named `reader`
59
60 @li The nested type meets the requirements of @b BodyWriter.
61
62 @tparam T The body type to test.
63
64 @par Example
65 @code
66 template<bool isRequest, class Body, class Fields>
67 void check_can_serialize(message<isRequest, Body, Fields> const&)
68 {
69 static_assert(is_body_writer<Body>::value,
70 "Cannot serialize Body, no reader");
71 }
72 @endcode
73 */
74 #if BOOST_BEAST_DOXYGEN
75 template<class T>
76 struct is_body_writer : std::integral_constant<bool, ...> {};
77 #else
78 template<class T, class = void>
79 struct is_body_writer : std::false_type {};
80
81 template<class T>
82 struct is_body_writer<T, beast::detail::void_t<
83 typename T::writer,
84 typename T::writer::const_buffers_type,
85 decltype(
86 std::declval<typename T::writer&>().init(std::declval<error_code&>()),
87 std::declval<boost::optional<std::pair<
88 typename T::writer::const_buffers_type, bool>>&>() =
89 std::declval<typename T::writer>().get(std::declval<error_code&>()),
90 (void)0)>> : std::integral_constant<bool,
91 boost::asio::is_const_buffer_sequence<
92 typename T::writer::const_buffers_type>::value && (
93 (std::is_constructible<typename T::writer,
94 header<true, detail::fields_model>&,
95 typename T::value_type&>::value &&
96 std::is_constructible<typename T::writer,
97 header<false, detail::fields_model>&,
98 typename T::value_type&>::value) ||
99 // Deprecated BodyWriter Concept (v1.66)
100 (std::is_constructible<typename T::writer,
101 message<true, T, detail::fields_model>&>::value &&
102 std::is_constructible<typename T::writer,
103 message<false, T, detail::fields_model>&>::value)
104 )
105 > {};
106 #endif
107
108 /** Determine if a @b Body type has a reader.
109
110 This metafunction is equivalent to `std::true_type` if:
111
112 @li `T` has a nested type named `reader`
113
114 @li The nested type meets the requirements of @b BodyReader.
115
116 @tparam T The body type to test.
117
118 @par Example
119 @code
120 template<bool isRequest, class Body, class Fields>
121 void check_can_parse(message<isRequest, Body, Fields>&)
122 {
123 static_assert(is_body_reader<Body>::value,
124 "Cannot parse Body, no reader");
125 }
126 @endcode
127 */
128 #if BOOST_BEAST_DOXYGEN
129 template<class T>
130 struct is_body_reader : std::integral_constant<bool, ...> {};
131 #else
132 template<class T, class = void>
133 struct is_body_reader : std::false_type {};
134
135 template<class T>
136 struct is_body_reader<T, beast::detail::void_t<decltype(
137 std::declval<typename T::reader&>().init(
138 boost::optional<std::uint64_t>(),
139 std::declval<error_code&>()),
140 std::declval<std::size_t&>() =
141 std::declval<typename T::reader&>().put(
142 std::declval<boost::asio::const_buffer>(),
143 std::declval<error_code&>()),
144 std::declval<typename T::reader&>().finish(
145 std::declval<error_code&>()),
146 (void)0)>> : std::integral_constant<bool,
147 (std::is_constructible<typename T::reader,
148 header<true, detail::fields_model>&,
149 typename T::value_type&>::value &&
150 std::is_constructible<typename T::reader,
151 header<false,detail::fields_model>&,
152 typename T::value_type&>::value) ||
153 // Deprecated BodyReader Concept (v1.66)
154 (std::is_constructible<typename T::reader,
155 message<true, T, detail::fields_model>&>::value &&
156 std::is_constructible<typename T::reader,
157 message<false, T, detail::fields_model>&>::value)
158 >
159 {
160 };
161 #endif
162
163 /** Determine if `T` meets the requirements of @b Fields
164
165 @tparam T The body type to test.
166
167 @par Example
168
169 Use with `static_assert`:
170
171 @code
172 template<bool isRequest, class Body, class Fields>
173 void f(message<isRequest, Body, Fields> const&)
174 {
175 static_assert(is_fields<Fields>::value,
176 "Fields requirements not met");
177 ...
178 @endcode
179
180 Use with `std::enable_if` (SFINAE):
181
182 @code
183 template<bool isRequest, class Body, class Fields>
184 typename std::enable_if<is_fields<Fields>::value>::type
185 f(message<isRequest, Body, Fields> const&);
186 @endcode
187 */
188 #if BOOST_BEAST_DOXYGEN
189 template<class T>
190 struct is_fields : std::integral_constant<bool, ...> {};
191 #else
192 template<class T>
193 using is_fields = typename detail::is_fields_helper<T>::type;
194 #endif
195
196 } // http
197 } // beast
198 } // boost
199
200 #endif