• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // execution/start.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_START_HPP
12 #define BOOST_ASIO_EXECUTION_START_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/traits/start_member.hpp>
21 #include <boost/asio/traits/start_free.hpp>
22 
23 #include <boost/asio/detail/push_options.hpp>
24 
25 #if defined(GENERATING_DOCUMENTATION)
26 
27 namespace boost {
28 namespace asio {
29 namespace execution {
30 
31 /// A customisation point that notifies an operation state object to start
32 /// its associated operation.
33 /**
34  * The name <tt>execution::start</tt> denotes a customisation point object.
35  * The expression <tt>execution::start(R)</tt> for some subexpression
36  * <tt>R</tt> is expression-equivalent to:
37  *
38  * @li <tt>R.start()</tt>, if that expression is valid.
39  *
40  * @li Otherwise, <tt>start(R)</tt>, if that expression is valid, with
41  * overload resolution performed in a context that includes the declaration
42  * <tt>void start();</tt> and that does not include a declaration of
43  * <tt>execution::start</tt>.
44  *
45  * @li Otherwise, <tt>execution::start(R)</tt> is ill-formed.
46  */
47 inline constexpr unspecified start = unspecified;
48 
49 /// A type trait that determines whether a @c start expression is
50 /// well-formed.
51 /**
52  * Class template @c can_start is a trait that is derived from
53  * @c true_type if the expression <tt>execution::start(std::declval<R>(),
54  * std::declval<E>())</tt> is well formed; otherwise @c false_type.
55  */
56 template <typename R>
57 struct can_start :
58   integral_constant<bool, automatically_determined>
59 {
60 };
61 
62 } // namespace execution
63 } // namespace asio
64 } // namespace boost
65 
66 #else // defined(GENERATING_DOCUMENTATION)
67 
68 namespace asio_execution_start_fn {
69 
70 using boost::asio::decay;
71 using boost::asio::declval;
72 using boost::asio::enable_if;
73 using boost::asio::traits::start_free;
74 using boost::asio::traits::start_member;
75 
76 void start();
77 
78 enum overload_type
79 {
80   call_member,
81   call_free,
82   ill_formed
83 };
84 
85 template <typename R, typename = void>
86 struct call_traits
87 {
88   BOOST_ASIO_STATIC_CONSTEXPR(overload_type, overload = ill_formed);
89   BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
90   typedef void result_type;
91 };
92 
93 template <typename R>
94 struct call_traits<R,
95   typename enable_if<
96     (
97       start_member<R>::is_valid
98     )
99   >::type> :
100   start_member<R>
101 {
102   BOOST_ASIO_STATIC_CONSTEXPR(overload_type, overload = call_member);
103 };
104 
105 template <typename R>
106 struct call_traits<R,
107   typename enable_if<
108     (
109       !start_member<R>::is_valid
110       &&
111       start_free<R>::is_valid
112     )
113   >::type> :
114   start_free<R>
115 {
116   BOOST_ASIO_STATIC_CONSTEXPR(overload_type, overload = call_free);
117 };
118 
119 struct impl
120 {
121 #if defined(BOOST_ASIO_HAS_MOVE)
122   template <typename R>
123   BOOST_ASIO_CONSTEXPR typename enable_if<
124     call_traits<R>::overload == call_member,
125     typename call_traits<R>::result_type
126   >::type
operator ()asio_execution_start_fn::impl127   operator()(R&& r) const
128     BOOST_ASIO_NOEXCEPT_IF((
129       call_traits<R>::is_noexcept))
130   {
131     return BOOST_ASIO_MOVE_CAST(R)(r).start();
132   }
133 
134   template <typename R>
135   BOOST_ASIO_CONSTEXPR typename enable_if<
136     call_traits<R>::overload == call_free,
137     typename call_traits<R>::result_type
138   >::type
operator ()asio_execution_start_fn::impl139   operator()(R&& r) const
140     BOOST_ASIO_NOEXCEPT_IF((
141       call_traits<R>::is_noexcept))
142   {
143     return start(BOOST_ASIO_MOVE_CAST(R)(r));
144   }
145 #else // defined(BOOST_ASIO_HAS_MOVE)
146   template <typename R>
147   BOOST_ASIO_CONSTEXPR typename enable_if<
148     call_traits<R&>::overload == call_member,
149     typename call_traits<R&>::result_type
150   >::type
151   operator()(R& r) const
152     BOOST_ASIO_NOEXCEPT_IF((
153       call_traits<R&>::is_noexcept))
154   {
155     return r.start();
156   }
157 
158   template <typename R>
159   BOOST_ASIO_CONSTEXPR typename enable_if<
160     call_traits<const R&>::overload == call_member,
161     typename call_traits<const R&>::result_type
162   >::type
163   operator()(const R& r) const
164     BOOST_ASIO_NOEXCEPT_IF((
165       call_traits<const R&>::is_noexcept))
166   {
167     return r.start();
168   }
169 
170   template <typename R>
171   BOOST_ASIO_CONSTEXPR typename enable_if<
172     call_traits<R&>::overload == call_free,
173     typename call_traits<R&>::result_type
174   >::type
175   operator()(R& r) const
176     BOOST_ASIO_NOEXCEPT_IF((
177       call_traits<R&>::is_noexcept))
178   {
179     return start(r);
180   }
181 
182   template <typename R>
183   BOOST_ASIO_CONSTEXPR typename enable_if<
184     call_traits<const R&>::overload == call_free,
185     typename call_traits<const R&>::result_type
186   >::type
187   operator()(const R& r) const
188     BOOST_ASIO_NOEXCEPT_IF((
189       call_traits<const R&>::is_noexcept))
190   {
191     return start(r);
192   }
193 #endif // defined(BOOST_ASIO_HAS_MOVE)
194 };
195 
196 template <typename T = impl>
197 struct static_instance
198 {
199   static const T instance;
200 };
201 
202 template <typename T>
203 const T static_instance<T>::instance = {};
204 
205 } // namespace asio_execution_start_fn
206 namespace boost {
207 namespace asio {
208 namespace execution {
209 namespace {
210 
211 static BOOST_ASIO_CONSTEXPR const asio_execution_start_fn::impl&
212   start = asio_execution_start_fn::static_instance<>::instance;
213 
214 } // namespace
215 
216 template <typename R>
217 struct can_start :
218   integral_constant<bool,
219     asio_execution_start_fn::call_traits<R>::overload !=
220       asio_execution_start_fn::ill_formed>
221 {
222 };
223 
224 #if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
225 
226 template <typename R>
227 constexpr bool can_start_v = can_start<R>::value;
228 
229 #endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
230 
231 template <typename R>
232 struct is_nothrow_start :
233   integral_constant<bool,
234     asio_execution_start_fn::call_traits<R>::is_noexcept>
235 {
236 };
237 
238 #if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
239 
240 template <typename R>
241 constexpr bool is_nothrow_start_v
242   = is_nothrow_start<R>::value;
243 
244 #endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
245 
246 } // namespace execution
247 } // namespace asio
248 } // namespace boost
249 
250 #endif // defined(GENERATING_DOCUMENTATION)
251 
252 #include <boost/asio/detail/pop_options.hpp>
253 
254 #endif // BOOST_ASIO_EXECUTION_START_HPP
255