Clementine
context_as.hpp
1 //
2 // execution/context_as.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_EXECUTION_CONTEXT_AS_HPP
12 #define ASIO_EXECUTION_CONTEXT_AS_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/execution/context.hpp"
21 #include "asio/execution/executor.hpp"
22 #include "asio/execution/scheduler.hpp"
23 #include "asio/execution/sender.hpp"
24 #include "asio/is_applicable_property.hpp"
25 #include "asio/query.hpp"
26 #include "asio/traits/query_static_constexpr_member.hpp"
27 #include "asio/traits/static_query.hpp"
28 
29 #include "asio/detail/push_options.hpp"
30 
31 namespace asio {
32 
33 #if defined(GENERATING_DOCUMENTATION)
34 
35 namespace execution {
36 
39 template <typename U>
40 struct context_as_t
41 {
43  template <typename T>
44  static constexpr bool is_applicable_property_v =
45  is_executor_v<T> || is_sender_v<T> || is_scheduler_v<T>;
46 
48  static constexpr bool is_requirable = false;
49 
51  static constexpr bool is_preferable = false;
52 
54  typedef T polymorphic_query_result_type;
55 };
56 
58 template <typename U>
59 constexpr context_as_t context_as;
60 
61 } // namespace execution
62 
63 #else // defined(GENERATING_DOCUMENTATION)
64 
65 namespace execution {
66 
67 template <typename T>
68 struct context_as_t
69 {
70 #if defined(ASIO_HAS_VARIABLE_TEMPLATES)
71  template <typename U>
72  ASIO_STATIC_CONSTEXPR(bool,
73  is_applicable_property_v = is_executor<U>::value
74  || is_sender<U>::value || is_scheduler<U>::value);
75 #endif // defined(ASIO_HAS_VARIABLE_TEMPLATES)
76 
77  ASIO_STATIC_CONSTEXPR(bool, is_requirable = false);
78  ASIO_STATIC_CONSTEXPR(bool, is_preferable = false);
79 
80  typedef T polymorphic_query_result_type;
81 
82  ASIO_CONSTEXPR context_as_t()
83  {
84  }
85 
86  ASIO_CONSTEXPR context_as_t(context_t)
87  {
88  }
89 
90 #if defined(ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
91  && defined(ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
92  template <typename E>
93  static ASIO_CONSTEXPR
94  typename traits::query_static_constexpr_member<E, context_t>::result_type
95  static_query()
96  ASIO_NOEXCEPT_IF((
97  traits::query_static_constexpr_member<E, context_t>::is_noexcept))
98  {
99  return traits::query_static_constexpr_member<E, context_t>::value();
100  }
101 
102  template <typename E, typename U = decltype(context_as_t::static_query<E>())>
103  static ASIO_CONSTEXPR const U static_query_v
104  = context_as_t::static_query<E>();
105 #endif // defined(ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
106  // && defined(ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
107 
108  template <typename Executor, typename U>
109  friend ASIO_CONSTEXPR U query(
110  const Executor& ex, const context_as_t<U>&,
111  typename enable_if<
112  is_same<T, U>::value
113  && can_query<const Executor&, const context_t&>::value
114  >::type* = 0)
115 #if !defined(__clang__) // Clang crashes if noexcept is used here.
116 #if defined(ASIO_MSVC) // Visual C++ wants the type to be qualified.
117  ASIO_NOEXCEPT_IF((
118  is_nothrow_query<const Executor&, const context_t&>::value))
119 #else // defined(ASIO_MSVC)
120  ASIO_NOEXCEPT_IF((
121  is_nothrow_query<const Executor&, const context_t&>::value))
122 #endif // defined(ASIO_MSVC)
123 #endif // !defined(__clang__)
124  {
125  return asio::query(ex, context);
126  }
127 };
128 
129 #if defined(ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
130  && defined(ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
131 template <typename T> template <typename E, typename U>
132 const U context_as_t<T>::static_query_v;
133 #endif // defined(ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
134  // && defined(ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
135 
136 #if (defined(ASIO_HAS_VARIABLE_TEMPLATES) \
137  && defined(ASIO_HAS_CONSTEXPR)) \
138  || defined(GENERATING_DOCUMENTATION)
139 template <typename T>
140 constexpr context_as_t<T> context_as{};
141 #endif // (defined(ASIO_HAS_VARIABLE_TEMPLATES)
142  // && defined(ASIO_HAS_CONSTEXPR))
143  // || defined(GENERATING_DOCUMENTATION)
144 
145 } // namespace execution
146 
147 #if !defined(ASIO_HAS_VARIABLE_TEMPLATES)
148 
149 template <typename T, typename U>
150 struct is_applicable_property<T, execution::context_as_t<U> >
151  : integral_constant<bool,
152  execution::is_executor<T>::value
153  || execution::is_sender<T>::value
154  || execution::is_scheduler<T>::value>
155 {
156 };
157 
158 #endif // !defined(ASIO_HAS_VARIABLE_TEMPLATES)
159 
160 namespace traits {
161 
162 #if !defined(ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
163  || !defined(ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
164 
165 template <typename T, typename U>
166 struct static_query<T, execution::context_as_t<U>,
167  typename enable_if<
168  static_query<T, execution::context_t>::is_valid
169  >::type> : static_query<T, execution::context_t>
170 {
171 };
172 
173 #endif // !defined(ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
174  // || !defined(ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
175 
176 #if !defined(ASIO_HAS_DEDUCED_QUERY_FREE_TRAIT)
177 
178 template <typename T, typename U>
179 struct query_free<T, execution::context_as_t<U>,
180  typename enable_if<
181  can_query<const T&, const execution::context_t&>::value
182  >::type>
183 {
184  ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
185  ASIO_STATIC_CONSTEXPR(bool, is_noexcept =
187 
188  typedef U result_type;
189 };
190 
191 #endif // !defined(ASIO_HAS_DEDUCED_QUERY_FREE_TRAIT)
192 
193 } // namespace traits
194 
195 #endif // defined(GENERATING_DOCUMENTATION)
196 
197 } // namespace asio
198 
199 #include "asio/detail/pop_options.hpp"
200 
201 #endif // ASIO_EXECUTION_CONTEXT_AS_HPP
Definition: query.hpp:269
Definition: static_query.hpp:42
Definition: type_traits.hpp:97
Definition: query_free.hpp:38
Definition: handler_work.hpp:37
Definition: is_applicable_property.hpp:46
Definition: any_io_executor.hpp:28