Clementine
query.hpp
1 //
2 // query.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 ASIO_QUERY_HPP
12 #define ASIO_QUERY_HPP
13 
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17 
18 #include "asio/detail/config.hpp"
19 #include "asio/detail/type_traits.hpp"
20 #include "asio/is_applicable_property.hpp"
21 #include "asio/traits/query_member.hpp"
22 #include "asio/traits/query_free.hpp"
23 #include "asio/traits/static_query.hpp"
24 
25 #include "asio/detail/push_options.hpp"
26 
27 #if defined(GENERATING_DOCUMENTATION)
28 
29 namespace asio {
30 
32 
57 inline constexpr unspecified query = unspecified;
58 
60 
65 template <typename T, typename Property>
66 struct can_query :
67  integral_constant<bool, automatically_determined>
68 {
69 };
70 
73 
78 template <typename T, typename Property>
79 struct is_nothrow_query :
80  integral_constant<bool, automatically_determined>
81 {
82 };
83 
85 
90 template <typename T, typename Property>
91 struct query_result
92 {
94  typedef automatically_determined type;
95 };
96 
97 } // namespace asio
98 
99 #else // defined(GENERATING_DOCUMENTATION)
100 
101 namespace asio_query_fn {
102 
103 using asio::decay;
104 using asio::declval;
105 using asio::enable_if;
110 
111 void query();
112 
113 enum overload_type
114 {
115  static_value,
116  call_member,
117  call_free,
118  ill_formed
119 };
120 
121 template <typename T, typename Properties, typename = void>
123 {
124  ASIO_STATIC_CONSTEXPR(overload_type, overload = ill_formed);
125  ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
126  typedef void result_type;
127 };
128 
129 template <typename T, typename Property>
130 struct call_traits<T, void(Property),
131  typename enable_if<
132  (
134  typename decay<T>::type,
135  typename decay<Property>::type
136  >::value
137  &&
138  static_query<T, Property>::is_valid
139  )
140  >::type> :
141  static_query<T, Property>
142 {
143  ASIO_STATIC_CONSTEXPR(overload_type, overload = static_value);
144 };
145 
146 template <typename T, typename Property>
147 struct call_traits<T, void(Property),
148  typename enable_if<
149  (
151  typename decay<T>::type,
152  typename decay<Property>::type
153  >::value
154  &&
155  !static_query<T, Property>::is_valid
156  &&
157  query_member<T, Property>::is_valid
158  )
159  >::type> :
160  query_member<T, Property>
161 {
162  ASIO_STATIC_CONSTEXPR(overload_type, overload = call_member);
163 };
164 
165 template <typename T, typename Property>
166 struct call_traits<T, void(Property),
167  typename enable_if<
168  (
170  typename decay<T>::type,
171  typename decay<Property>::type
172  >::value
173  &&
174  !static_query<T, Property>::is_valid
175  &&
176  !query_member<T, Property>::is_valid
177  &&
178  query_free<T, Property>::is_valid
179  )
180  >::type> :
181  query_free<T, Property>
182 {
183  ASIO_STATIC_CONSTEXPR(overload_type, overload = call_free);
184 };
185 
186 struct impl
187 {
188  template <typename T, typename Property>
189  ASIO_NODISCARD ASIO_CONSTEXPR typename enable_if<
191  typename call_traits<T, void(Property)>::result_type
192  >::type
193  operator()(
194  ASIO_MOVE_ARG(T),
195  ASIO_MOVE_ARG(Property)) const
196  ASIO_NOEXCEPT_IF((
197  call_traits<T, void(Property)>::is_noexcept))
198  {
199  return static_query<
200  typename decay<T>::type,
201  typename decay<Property>::type
202  >::value();
203  }
204 
205  template <typename T, typename Property>
206  ASIO_NODISCARD ASIO_CONSTEXPR typename enable_if<
207  call_traits<T, void(Property)>::overload == call_member,
208  typename call_traits<T, void(Property)>::result_type
209  >::type
210  operator()(
211  ASIO_MOVE_ARG(T) t,
212  ASIO_MOVE_ARG(Property) p) const
213  ASIO_NOEXCEPT_IF((
214  call_traits<T, void(Property)>::is_noexcept))
215  {
216  return ASIO_MOVE_CAST(T)(t).query(ASIO_MOVE_CAST(Property)(p));
217  }
218 
219  template <typename T, typename Property>
220  ASIO_NODISCARD ASIO_CONSTEXPR typename enable_if<
221  call_traits<T, void(Property)>::overload == call_free,
222  typename call_traits<T, void(Property)>::result_type
223  >::type
224  operator()(
225  ASIO_MOVE_ARG(T) t,
226  ASIO_MOVE_ARG(Property) p) const
227  ASIO_NOEXCEPT_IF((
228  call_traits<T, void(Property)>::is_noexcept))
229  {
230  return query(ASIO_MOVE_CAST(T)(t), ASIO_MOVE_CAST(Property)(p));
231  }
232 };
233 
234 template <typename T = impl>
236 {
237  static const T instance;
238 };
239 
240 template <typename T>
241 const T static_instance<T>::instance = {};
242 
243 } // namespace asio_query_fn
244 namespace asio {
245 namespace {
246 
247 static ASIO_CONSTEXPR const asio_query_fn::impl&
249 
250 } // namespace
251 
252 template <typename T, typename Property>
253 struct can_query :
254  integral_constant<bool,
255  asio_query_fn::call_traits<T, void(Property)>::overload !=
256  asio_query_fn::ill_formed>
257 {
258 };
259 
260 #if defined(ASIO_HAS_VARIABLE_TEMPLATES)
261 
262 template <typename T, typename Property>
263 constexpr bool can_query_v
265 
266 #endif // defined(ASIO_HAS_VARIABLE_TEMPLATES)
267 
268 template <typename T, typename Property>
270  integral_constant<bool,
271  asio_query_fn::call_traits<T, void(Property)>::is_noexcept>
272 {
273 };
274 
275 #if defined(ASIO_HAS_VARIABLE_TEMPLATES)
276 
277 template <typename T, typename Property>
278 constexpr bool is_nothrow_query_v
280 
281 #endif // defined(ASIO_HAS_VARIABLE_TEMPLATES)
282 
283 template <typename T, typename Property>
285 {
286  typedef typename asio_query_fn::call_traits<
287  T, void(Property)>::result_type type;
288 };
289 
290 } // namespace asio
291 
292 #endif // defined(GENERATING_DOCUMENTATION)
293 
294 #include "asio/detail/pop_options.hpp"
295 
296 #endif // ASIO_QUERY_HPP
Definition: query.hpp:235
Definition: query.hpp:269
Definition: query.hpp:101
Definition: query_member.hpp:38
Definition: static_query.hpp:42
Definition: query.hpp:284
Definition: type_traits.hpp:97
Definition: query.hpp:253
Definition: query.hpp:122
Definition: query_free.hpp:38
Definition: query.hpp:186
Definition: is_applicable_property.hpp:46
Definition: any_io_executor.hpp:28