Clementine
context.hpp
1 //
2 // execution/context.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_CONTEXT2_HPP
12 #define ASIO_EXECUTION_CONTEXT2_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/executor.hpp"
21 #include "asio/execution/scheduler.hpp"
22 #include "asio/execution/sender.hpp"
23 #include "asio/is_applicable_property.hpp"
24 #include "asio/traits/query_static_constexpr_member.hpp"
25 #include "asio/traits/static_query.hpp"
26 
27 #if defined(ASIO_HAS_STD_ANY)
28 # include <any>
29 #endif // defined(ASIO_HAS_STD_ANY)
30 
31 #include "asio/detail/push_options.hpp"
32 
33 namespace asio {
34 
35 #if defined(GENERATING_DOCUMENTATION)
36 
37 namespace execution {
38 
41 struct context_t
42 {
44  template <typename T>
45  static constexpr bool is_applicable_property_v =
46  is_executor_v<T> || is_sender_v<T> || is_scheduler_v<T>;
47 
49  static constexpr bool is_requirable = false;
50 
52  static constexpr bool is_preferable = false;
53 
55  typedef std::any polymorphic_query_result_type;
56 };
57 
59 constexpr context_t context;
60 
61 } // namespace execution
62 
63 #else // defined(GENERATING_DOCUMENTATION)
64 
65 namespace execution {
66 namespace detail {
67 
68 template <int I = 0>
69 struct context_t
70 {
71 #if defined(ASIO_HAS_VARIABLE_TEMPLATES)
72  template <typename T>
73  ASIO_STATIC_CONSTEXPR(bool,
74  is_applicable_property_v = is_executor<T>::value
76 #endif // defined(ASIO_HAS_VARIABLE_TEMPLATES)
77 
78  ASIO_STATIC_CONSTEXPR(bool, is_requirable = false);
79  ASIO_STATIC_CONSTEXPR(bool, is_preferable = false);
80 
81 #if defined(ASIO_HAS_STD_ANY)
82  typedef std::any polymorphic_query_result_type;
83 #endif // defined(ASIO_HAS_STD_ANY)
84 
85  ASIO_CONSTEXPR context_t()
86  {
87  }
88 
89 #if defined(ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
90  && defined(ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
91  template <typename T>
92  static ASIO_CONSTEXPR
94  static_query()
95  ASIO_NOEXCEPT_IF((
97  {
99  }
100 
101  template <typename E, typename T = decltype(context_t::static_query<E>())>
102  static ASIO_CONSTEXPR const T static_query_v
103  = context_t::static_query<E>();
104 #endif // defined(ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
105  // && defined(ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
106 
107 #if !defined(ASIO_HAS_CONSTEXPR)
108  static const context_t instance;
109 #endif // !defined(ASIO_HAS_CONSTEXPR)
110 };
111 
112 #if defined(ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
113  && defined(ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
114 template <int I> template <typename E, typename T>
116 #endif // defined(ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
117  // && defined(ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
118 
119 #if !defined(ASIO_HAS_CONSTEXPR)
120 template <int I>
122 #endif
123 
124 } // namespace detail
125 
127 
128 #if defined(ASIO_HAS_CONSTEXPR) || defined(GENERATING_DOCUMENTATION)
129 constexpr context_t context;
130 #else // defined(ASIO_HAS_CONSTEXPR) || defined(GENERATING_DOCUMENTATION)
131 namespace { static const context_t& context = context_t::instance; }
132 #endif
133 
134 } // namespace execution
135 
136 #if !defined(ASIO_HAS_VARIABLE_TEMPLATES)
137 
138 template <typename T>
139 struct is_applicable_property<T, execution::context_t>
140  : integral_constant<bool,
141  execution::is_executor<T>::value
142  || execution::is_sender<T>::value
143  || execution::is_scheduler<T>::value>
144 {
145 };
146 
147 #endif // !defined(ASIO_HAS_VARIABLE_TEMPLATES)
148 
149 namespace traits {
150 
151 #if !defined(ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
152  || !defined(ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
153 
154 template <typename T>
155 struct static_query<T, execution::context_t,
156  typename enable_if<
157  traits::query_static_constexpr_member<T,
158  execution::context_t>::is_valid
159  >::type>
160 {
161  ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
162  ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
163 
164  typedef typename traits::query_static_constexpr_member<T,
165  execution::context_t>::result_type result_type;
166 
167  static ASIO_CONSTEXPR result_type value()
168  {
170  execution::context_t>::value();
171  }
172 };
173 
174 #endif // !defined(ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
175  // || !defined(ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
176 
177 } // namespace traits
178 
179 #endif // defined(GENERATING_DOCUMENTATION)
180 
181 } // namespace asio
182 
183 #include "asio/detail/pop_options.hpp"
184 
185 #endif // ASIO_EXECUTION_CONTEXT2_HPP
Definition: any_executor.hpp:249
The is_scheduler trait detects whether a type T satisfies the execution::scheduler concept...
Definition: scheduler.hpp:48
The is_sender trait detects whether a type T satisfies the execution::sender concept.
Definition: sender.hpp:183
Definition: static_query.hpp:42
Definition: chrono.h:284
Definition: type_traits.hpp:97
Definition: query_static_constexpr_member.hpp:42
Definition: any_executor.hpp:256
Definition: handler_work.hpp:37
Definition: is_applicable_property.hpp:46
Definition: context.hpp:69
Definition: any_io_executor.hpp:28
The is_executor trait detects whether a type T satisfies the execution::executor concept.
Definition: executor.hpp:109