5 // Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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)
11 #ifndef BOOST_ASIO_ANY_IO_EXECUTOR_HPP
12 #define BOOST_ASIO_ANY_IO_EXECUTOR_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/config.hpp>
19 #if defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT)
20 # include <boost/asio/executor.hpp>
21 #else // defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT)
22 # include <boost/asio/execution.hpp>
23 # include <boost/asio/execution_context.hpp>
24 #endif // defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT)
26 #include <boost/asio/detail/push_options.hpp>
31 #if defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT)
33 typedef executor any_io_executor;
35 #else // defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT)
37 /// Polymorphic executor type for use with I/O objects.
39 * The @c any_io_executor type is a polymorphic executor that supports the set
40 * of properties required by I/O objects. It is defined as the
41 * execution::any_executor class template parameterised as follows:
42 * @code execution::any_executor<
43 * execution::context_as_t<execution_context&>,
44 * execution::blocking_t::never_t,
45 * execution::prefer_only<execution::blocking_t::possibly_t>,
46 * execution::prefer_only<execution::outstanding_work_t::tracked_t>,
47 * execution::prefer_only<execution::outstanding_work_t::untracked_t>,
48 * execution::prefer_only<execution::relationship_t::fork_t>,
49 * execution::prefer_only<execution::relationship_t::continuation_t>
52 class any_io_executor :
53 #if defined(GENERATING_DOCUMENTATION)
54 public execution::any_executor<...>
55 #else // defined(GENERATING_DOCUMENTATION)
56 public execution::any_executor<
57 execution::context_as_t<execution_context&>,
58 execution::blocking_t::never_t,
59 execution::prefer_only<execution::blocking_t::possibly_t>,
60 execution::prefer_only<execution::outstanding_work_t::tracked_t>,
61 execution::prefer_only<execution::outstanding_work_t::untracked_t>,
62 execution::prefer_only<execution::relationship_t::fork_t>,
63 execution::prefer_only<execution::relationship_t::continuation_t>
65 #endif // defined(GENERATING_DOCUMENTATION)
68 #if !defined(GENERATING_DOCUMENTATION)
69 typedef execution::any_executor<
70 execution::context_as_t<execution_context&>,
71 execution::blocking_t::never_t,
72 execution::prefer_only<execution::blocking_t::possibly_t>,
73 execution::prefer_only<execution::outstanding_work_t::tracked_t>,
74 execution::prefer_only<execution::outstanding_work_t::untracked_t>,
75 execution::prefer_only<execution::relationship_t::fork_t>,
76 execution::prefer_only<execution::relationship_t::continuation_t>
79 typedef void supportable_properties_type(
80 execution::context_as_t<execution_context&>,
81 execution::blocking_t::never_t,
82 execution::prefer_only<execution::blocking_t::possibly_t>,
83 execution::prefer_only<execution::outstanding_work_t::tracked_t>,
84 execution::prefer_only<execution::outstanding_work_t::untracked_t>,
85 execution::prefer_only<execution::relationship_t::fork_t>,
86 execution::prefer_only<execution::relationship_t::continuation_t>
88 #endif // !defined(GENERATING_DOCUMENTATION)
90 /// Default constructor.
91 BOOST_ASIO_DECL any_io_executor() BOOST_ASIO_NOEXCEPT;
93 /// Construct in an empty state. Equivalent effects to default constructor.
94 BOOST_ASIO_DECL any_io_executor(nullptr_t) BOOST_ASIO_NOEXCEPT;
97 BOOST_ASIO_DECL any_io_executor(const any_io_executor& e) BOOST_ASIO_NOEXCEPT;
99 #if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
100 /// Move constructor.
101 BOOST_ASIO_DECL any_io_executor(any_io_executor&& e) BOOST_ASIO_NOEXCEPT;
102 #endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
104 /// Construct to point to the same target as another any_executor.
105 #if defined(GENERATING_DOCUMENTATION)
106 template <class... OtherSupportableProperties>
107 any_io_executor(execution::any_executor<OtherSupportableProperties...> e);
108 #else // defined(GENERATING_DOCUMENTATION)
109 template <typename OtherAnyExecutor>
110 any_io_executor(OtherAnyExecutor e,
113 !is_same<OtherAnyExecutor, any_io_executor>::value
114 && is_base_of<execution::detail::any_executor_base,
115 OtherAnyExecutor>::value,
116 typename execution::detail::supportable_properties<
117 0, supportable_properties_type>::template
118 is_valid_target<OtherAnyExecutor>,
122 : base_type(BOOST_ASIO_MOVE_CAST(OtherAnyExecutor)(e))
125 #endif // defined(GENERATING_DOCUMENTATION)
127 /// Construct a polymorphic wrapper for the specified executor.
128 #if defined(GENERATING_DOCUMENTATION)
129 template <BOOST_ASIO_EXECUTION_EXECUTOR Executor>
130 any_io_executor(Executor e);
131 #else // defined(GENERATING_DOCUMENTATION)
132 template <BOOST_ASIO_EXECUTION_EXECUTOR Executor>
133 any_io_executor(Executor e,
136 !is_same<Executor, any_io_executor>::value
137 && !is_base_of<execution::detail::any_executor_base,
139 execution::detail::is_valid_target_executor<
140 Executor, supportable_properties_type>,
144 : base_type(BOOST_ASIO_MOVE_CAST(Executor)(e))
147 #endif // defined(GENERATING_DOCUMENTATION)
149 /// Assignment operator.
150 BOOST_ASIO_DECL any_io_executor& operator=(
151 const any_io_executor& e) BOOST_ASIO_NOEXCEPT;
153 #if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
154 /// Move assignment operator.
155 BOOST_ASIO_DECL any_io_executor& operator=(
156 any_io_executor&& e) BOOST_ASIO_NOEXCEPT;
157 #endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
159 /// Assignment operator that sets the polymorphic wrapper to the empty state.
160 BOOST_ASIO_DECL any_io_executor& operator=(nullptr_t);
163 BOOST_ASIO_DECL ~any_io_executor();
165 /// Swap targets with another polymorphic wrapper.
166 BOOST_ASIO_DECL void swap(any_io_executor& other) BOOST_ASIO_NOEXCEPT;
168 /// Obtain a polymorphic wrapper with the specified property.
170 * Do not call this function directly. It is intended for use with the
171 * boost::asio::require and boost::asio::prefer customisation points.
174 * @code any_io_executor ex = ...;
175 * auto ex2 = boost::asio::require(ex, execution::blocking.possibly); @endcode
177 template <typename Property>
178 any_io_executor require(const Property& p,
180 traits::require_member<const base_type&, const Property&>::is_valid
183 return static_cast<const base_type&>(*this).require(p);
186 /// Obtain a polymorphic wrapper with the specified property.
188 * Do not call this function directly. It is intended for use with the
189 * boost::asio::prefer customisation point.
192 * @code any_io_executor ex = ...;
193 * auto ex2 = boost::asio::prefer(ex, execution::blocking.possibly); @endcode
195 template <typename Property>
196 any_io_executor prefer(const Property& p,
198 traits::prefer_member<const base_type&, const Property&>::is_valid
201 return static_cast<const base_type&>(*this).prefer(p);
205 #if !defined(GENERATING_DOCUMENTATION)
208 BOOST_ASIO_DECL any_io_executor any_io_executor::require(
209 const execution::blocking_t::never_t&, int) const;
212 BOOST_ASIO_DECL any_io_executor any_io_executor::prefer(
213 const execution::blocking_t::possibly_t&, int) const;
216 BOOST_ASIO_DECL any_io_executor any_io_executor::prefer(
217 const execution::outstanding_work_t::tracked_t&, int) const;
220 BOOST_ASIO_DECL any_io_executor any_io_executor::prefer(
221 const execution::outstanding_work_t::untracked_t&, int) const;
224 BOOST_ASIO_DECL any_io_executor any_io_executor::prefer(
225 const execution::relationship_t::fork_t&, int) const;
228 BOOST_ASIO_DECL any_io_executor any_io_executor::prefer(
229 const execution::relationship_t::continuation_t&, int) const;
233 #if !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
236 struct equality_comparable<any_io_executor>
238 static const bool is_valid = true;
239 static const bool is_noexcept = true;
242 #endif // !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
244 #if !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
246 template <typename F>
247 struct execute_member<any_io_executor, F>
249 static const bool is_valid = true;
250 static const bool is_noexcept = false;
251 typedef void result_type;
254 #endif // !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
256 #if !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
258 template <typename Prop>
259 struct query_member<any_io_executor, Prop> :
260 query_member<any_io_executor::base_type, Prop>
264 #endif // !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
266 #if !defined(BOOST_ASIO_HAS_DEDUCED_REQUIRE_MEMBER_TRAIT)
268 template <typename Prop>
269 struct require_member<any_io_executor, Prop> :
270 require_member<any_io_executor::base_type, Prop>
272 typedef any_io_executor result_type;
275 #endif // !defined(BOOST_ASIO_HAS_DEDUCED_REQUIRE_MEMBER_TRAIT)
277 #if !defined(BOOST_ASIO_HAS_DEDUCED_PREFER_MEMBER_TRAIT)
279 template <typename Prop>
280 struct prefer_member<any_io_executor, Prop> :
281 prefer_member<any_io_executor::base_type, Prop>
283 typedef any_io_executor result_type;
286 #endif // !defined(BOOST_ASIO_HAS_DEDUCED_PREFER_MEMBER_TRAIT)
288 } // namespace traits
290 #endif // !defined(GENERATING_DOCUMENTATION)
292 #endif // defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT)
297 #include <boost/asio/detail/pop_options.hpp>
299 #if defined(BOOST_ASIO_HEADER_ONLY) \
300 && !defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT)
301 # include <boost/asio/impl/any_io_executor.ipp>
302 #endif // defined(BOOST_ASIO_HEADER_ONLY)
303 // && !defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT)
305 #endif // BOOST_ASIO_ANY_IO_EXECUTOR_HPP