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

source code of boost/libs/asio/include/boost/asio/execution/context.hpp