• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 BOOST_ASIO_EXECUTION_CONTEXT2_HPP
12 #define BOOST_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 <boost/asio/detail/config.hpp>
19 #include <boost/asio/detail/type_traits.hpp>
20 #include <boost/asio/execution/executor.hpp>
21 #include <boost/asio/execution/scheduler.hpp>
22 #include <boost/asio/execution/sender.hpp>
23 #include <boost/asio/is_applicable_property.hpp>
24 #include <boost/asio/traits/query_static_constexpr_member.hpp>
25 #include <boost/asio/traits/static_query.hpp>
26 
27 #if defined(BOOST_ASIO_HAS_STD_ANY)
28 # include <any>
29 #endif // defined(BOOST_ASIO_HAS_STD_ANY)
30 
31 #include <boost/asio/detail/push_options.hpp>
32 
33 namespace boost {
34 namespace asio {
35 
36 #if defined(GENERATING_DOCUMENTATION)
37 
38 namespace execution {
39 
40 /// A property that is used to obtain the execution context that is associated
41 /// with an executor.
42 struct context_t
43 {
44   /// The context_t property applies to executors, senders, and schedulers.
45   template <typename T>
46   static constexpr bool is_applicable_property_v =
47     is_executor_v<T> || is_sender_v<T> || is_scheduler_v<T>;
48 
49   /// The context_t property cannot be required.
50   static constexpr bool is_requirable = false;
51 
52   /// The context_t property cannot be preferred.
53   static constexpr bool is_preferable = false;
54 
55   /// The type returned by queries against an @c any_executor.
56   typedef std::any polymorphic_query_result_type;
57 };
58 
59 /// A special value used for accessing the context_t property.
60 constexpr context_t context;
61 
62 } // namespace execution
63 
64 #else // defined(GENERATING_DOCUMENTATION)
65 
66 namespace execution {
67 namespace detail {
68 
69 template <int I = 0>
70 struct context_t
71 {
72 #if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
73   template <typename T>
74   BOOST_ASIO_STATIC_CONSTEXPR(bool,
75     is_applicable_property_v = is_executor<T>::value
76       || is_sender<T>::value || is_scheduler<T>::value);
77 #endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
78 
79   BOOST_ASIO_STATIC_CONSTEXPR(bool, is_requirable = false);
80   BOOST_ASIO_STATIC_CONSTEXPR(bool, is_preferable = false);
81 
82 #if defined(BOOST_ASIO_HAS_STD_ANY)
83   typedef std::any polymorphic_query_result_type;
84 #endif // defined(BOOST_ASIO_HAS_STD_ANY)
85 
86   BOOST_ASIO_CONSTEXPR context_t()
87   {
88   }
89 
90 #if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
91   && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
92   template <typename T>
93   static BOOST_ASIO_CONSTEXPR
94   typename traits::query_static_constexpr_member<T, context_t>::result_type
95   static_query()
96     BOOST_ASIO_NOEXCEPT_IF((
97       traits::query_static_constexpr_member<T, context_t>::is_noexcept))
98   {
99     return traits::query_static_constexpr_member<T, context_t>::value();
100   }
101 
102   template <typename E, typename T = decltype(context_t::static_query<E>())>
103   static BOOST_ASIO_CONSTEXPR const T static_query_v
104     = context_t::static_query<E>();
105 #endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
106        //   && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
107 
108 #if !defined(BOOST_ASIO_HAS_CONSTEXPR)
109   static const context_t instance;
110 #endif // !defined(BOOST_ASIO_HAS_CONSTEXPR)
111 };
112 
113 #if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
114   && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
115 template <int I> template <typename E, typename T>
116 const T context_t<I>::static_query_v;
117 #endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
118        //   && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
119 
120 #if !defined(BOOST_ASIO_HAS_CONSTEXPR)
121 template <int I>
122 const context_t<I> context_t<I>::instance;
123 #endif
124 
125 } // namespace detail
126 
127 typedef detail::context_t<> context_t;
128 
129 #if defined(BOOST_ASIO_HAS_CONSTEXPR) || defined(GENERATING_DOCUMENTATION)
130 constexpr context_t context;
131 #else // defined(BOOST_ASIO_HAS_CONSTEXPR) || defined(GENERATING_DOCUMENTATION)
132 namespace { static const context_t& context = context_t::instance; }
133 #endif
134 
135 } // namespace execution
136 
137 #if !defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
138 
139 template <typename T>
140 struct is_applicable_property<T, execution::context_t>
141   : integral_constant<bool,
142       execution::is_executor<T>::value
143         || execution::is_sender<T>::value
144         || execution::is_scheduler<T>::value>
145 {
146 };
147 
148 #endif // !defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
149 
150 namespace traits {
151 
152 #if !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
153   || !defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
154 
155 template <typename T>
156 struct static_query<T, execution::context_t,
157   typename enable_if<
158     traits::query_static_constexpr_member<T,
159       execution::context_t>::is_valid
160   >::type>
161 {
162   BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
163   BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
164 
165   typedef typename traits::query_static_constexpr_member<T,
166     execution::context_t>::result_type result_type;
167 
168   static BOOST_ASIO_CONSTEXPR result_type value()
169   {
170     return traits::query_static_constexpr_member<T,
171       execution::context_t>::value();
172   }
173 };
174 
175 #endif // !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
176        //   || !defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
177 
178 } // namespace traits
179 
180 #endif // defined(GENERATING_DOCUMENTATION)
181 
182 } // namespace asio
183 } // namespace boost
184 
185 #include <boost/asio/detail/pop_options.hpp>
186 
187 #endif // BOOST_ASIO_EXECUTION_CONTEXT2_HPP
188