1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
//
// this_coro.hpp
// ~~~~~~~~~~~~~
//
// Copyright (c) 2003-2025 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_ASIO_THIS_CORO_HPP
#define BOOST_ASIO_THIS_CORO_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace this_coro {
/// Awaitable type that returns the executor of the current coroutine.
struct executor_t
{
constexpr executor_t()
{
}
};
/// Awaitable object that returns the executor of the current coroutine.
BOOST_ASIO_INLINE_VARIABLE constexpr executor_t executor;
/// Awaitable type that returns the cancellation state of the current coroutine.
struct cancellation_state_t
{
constexpr cancellation_state_t()
{
}
};
/// Awaitable object that returns the cancellation state of the current
/// coroutine.
/**
* @par Example
* @code boost::asio::awaitable<void> my_coroutine()
* {
* boost::asio::cancellation_state cs
* = co_await boost::asio::this_coro::cancellation_state;
*
* // ...
*
* if (cs.cancelled() != boost::asio::cancellation_type::none)
* // ...
* } @endcode
*/
BOOST_ASIO_INLINE_VARIABLE constexpr cancellation_state_t cancellation_state;
#if defined(GENERATING_DOCUMENTATION)
/// Returns an awaitable object that may be used to reset the cancellation state
/// of the current coroutine.
/**
* Let <tt>P</tt> be the cancellation slot associated with the current
* coroutine's @ref co_spawn completion handler. Assigns a new
* boost::asio::cancellation_state object <tt>S</tt>, constructed as
* <tt>S(P)</tt>, into the current coroutine's cancellation state object.
*
* @par Example
* @code boost::asio::awaitable<void> my_coroutine()
* {
* co_await boost::asio::this_coro::reset_cancellation_state();
*
* // ...
* } @endcode
*
* @note The cancellation state is shared by all coroutines in the same "thread
* of execution" that was created using boost::asio::co_spawn.
*/
BOOST_ASIO_NODISCARD constexpr unspecified
reset_cancellation_state();
/// Returns an awaitable object that may be used to reset the cancellation state
/// of the current coroutine.
/**
* Let <tt>P</tt> be the cancellation slot associated with the current
* coroutine's @ref co_spawn completion handler. Assigns a new
* boost::asio::cancellation_state object <tt>S</tt>, constructed as <tt>S(P,
* std::forward<Filter>(filter))</tt>, into the current coroutine's
* cancellation state object.
*
* @par Example
* @code boost::asio::awaitable<void> my_coroutine()
* {
* co_await boost::asio::this_coro::reset_cancellation_state(
* boost::asio::enable_partial_cancellation());
*
* // ...
* } @endcode
*
* @note The cancellation state is shared by all coroutines in the same "thread
* of execution" that was created using boost::asio::co_spawn.
*/
template <typename Filter>
BOOST_ASIO_NODISCARD constexpr unspecified
reset_cancellation_state(Filter&& filter);
/// Returns an awaitable object that may be used to reset the cancellation state
/// of the current coroutine.
/**
* Let <tt>P</tt> be the cancellation slot associated with the current
* coroutine's @ref co_spawn completion handler. Assigns a new
* boost::asio::cancellation_state object <tt>S</tt>, constructed as <tt>S(P,
* std::forward<InFilter>(in_filter),
* std::forward<OutFilter>(out_filter))</tt>, into the current coroutine's
* cancellation state object.
*
* @par Example
* @code boost::asio::awaitable<void> my_coroutine()
* {
* co_await boost::asio::this_coro::reset_cancellation_state(
* boost::asio::enable_partial_cancellation(),
* boost::asio::disable_cancellation());
*
* // ...
* } @endcode
*
* @note The cancellation state is shared by all coroutines in the same "thread
* of execution" that was created using boost::asio::co_spawn.
*/
template <typename InFilter, typename OutFilter>
BOOST_ASIO_NODISCARD constexpr unspecified
reset_cancellation_state(
InFilter&& in_filter,
OutFilter&& out_filter);
/// Returns an awaitable object that may be used to determine whether the
/// coroutine throws if trying to suspend when it has been cancelled.
/**
* @par Example
* @code boost::asio::awaitable<void> my_coroutine()
* {
* if (co_await boost::asio::this_coro::throw_if_cancelled)
* // ...
*
* // ...
* } @endcode
*/
BOOST_ASIO_NODISCARD constexpr unspecified
throw_if_cancelled();
/// Returns an awaitable object that may be used to specify whether the
/// coroutine throws if trying to suspend when it has been cancelled.
/**
* @par Example
* @code boost::asio::awaitable<void> my_coroutine()
* {
* co_await boost::asio::this_coro::throw_if_cancelled(false);
*
* // ...
* } @endcode
*/
BOOST_ASIO_NODISCARD constexpr unspecified
throw_if_cancelled(bool value);
#else // defined(GENERATING_DOCUMENTATION)
struct reset_cancellation_state_0_t
{
constexpr reset_cancellation_state_0_t()
{
}
};
BOOST_ASIO_NODISCARD inline constexpr reset_cancellation_state_0_t
reset_cancellation_state()
{
return reset_cancellation_state_0_t();
}
template <typename Filter>
struct reset_cancellation_state_1_t
{
template <typename F>
explicit constexpr reset_cancellation_state_1_t(
F&& filt)
: filter(static_cast<F&&>(filt))
{
}
Filter filter;
};
template <typename Filter>
BOOST_ASIO_NODISCARD inline constexpr reset_cancellation_state_1_t<
decay_t<Filter>>
reset_cancellation_state(Filter&& filter)
{
return reset_cancellation_state_1_t<decay_t<Filter>>(
static_cast<Filter&&>(filter));
}
template <typename InFilter, typename OutFilter>
struct reset_cancellation_state_2_t
{
template <typename F1, typename F2>
constexpr reset_cancellation_state_2_t(
F1&& in_filt, F2&& out_filt)
: in_filter(static_cast<F1&&>(in_filt)),
out_filter(static_cast<F2&&>(out_filt))
{
}
InFilter in_filter;
OutFilter out_filter;
};
template <typename InFilter, typename OutFilter>
BOOST_ASIO_NODISCARD inline constexpr
reset_cancellation_state_2_t<decay_t<InFilter>, decay_t<OutFilter>>
reset_cancellation_state(InFilter&& in_filter, OutFilter&& out_filter)
{
return reset_cancellation_state_2_t<decay_t<InFilter>, decay_t<OutFilter>>(
static_cast<InFilter&&>(in_filter),
static_cast<OutFilter&&>(out_filter));
}
struct throw_if_cancelled_0_t
{
constexpr throw_if_cancelled_0_t()
{
}
};
BOOST_ASIO_NODISCARD inline constexpr throw_if_cancelled_0_t
throw_if_cancelled()
{
return throw_if_cancelled_0_t();
}
struct throw_if_cancelled_1_t
{
explicit constexpr throw_if_cancelled_1_t(bool val)
: value(val)
{
}
bool value;
};
BOOST_ASIO_NODISCARD inline constexpr throw_if_cancelled_1_t
throw_if_cancelled(bool value)
{
return throw_if_cancelled_1_t(value);
}
#endif // defined(GENERATING_DOCUMENTATION)
} // namespace this_coro
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_THIS_CORO_HPP