deferred.hpp
21 KB
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
//
// deferred.hpp
// ~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 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_DEFERRED_HPP
#define BOOST_ASIO_DEFERRED_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#if (defined(BOOST_ASIO_HAS_STD_TUPLE) \
&& defined(BOOST_ASIO_HAS_DECLTYPE) \
&& defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)) \
|| defined(GENERATING_DOCUMENTATION)
#include <tuple>
#include <boost/asio/associator.hpp>
#include <boost/asio/async_result.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/asio/detail/utility.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
/// Trait for detecting objects that are usable as deferred operations.
template <typename T>
struct is_deferred : false_type
{
};
namespace detail {
// Helper trait for getting the completion signature of the tail in a sequence
// when invoked with the specified arguments.
template <typename HeadSignature, typename Tail>
struct deferred_sequence_signature;
template <typename R, typename... Args, typename Tail>
struct deferred_sequence_signature<R(Args...), Tail>
{
static_assert(
!is_same<decltype(declval<Tail>()(declval<Args>()...)), void>::value,
"deferred functions must produce a deferred return type");
typedef typename completion_signature_of<
decltype(declval<Tail>()(declval<Args>()...))>::type type;
};
// Completion handler for the head component of a deferred sequence.
template <typename Handler, typename Tail>
class deferred_sequence_handler
{
public:
template <typename H, typename T>
explicit deferred_sequence_handler(
BOOST_ASIO_MOVE_ARG(H) handler, BOOST_ASIO_MOVE_ARG(T) tail)
: handler_(BOOST_ASIO_MOVE_CAST(H)(handler)),
tail_(BOOST_ASIO_MOVE_CAST(T)(tail))
{
}
template <typename... Args>
void operator()(BOOST_ASIO_MOVE_ARG(Args)... args)
{
BOOST_ASIO_MOVE_OR_LVALUE(Tail)(tail_)(
BOOST_ASIO_MOVE_CAST(Args)(args)...)(
BOOST_ASIO_MOVE_OR_LVALUE(Handler)(handler_));
}
//private:
Handler handler_;
Tail tail_;
};
} // namespace detail
/// Used to represent an empty deferred action.
struct deferred_noop
{
/// No effect.
template <typename... Args>
void operator()(BOOST_ASIO_MOVE_ARG(Args)...) BOOST_ASIO_RVALUE_REF_QUAL
{
}
#if defined(BOOST_ASIO_HAS_REF_QUALIFIED_FUNCTIONS)
/// No effect.
template <typename... Args>
void operator()(BOOST_ASIO_MOVE_ARG(Args)...) const &
{
}
#endif // defined(BOOST_ASIO_HAS_REF_QUALIFIED_FUNCTIONS)
};
#if !defined(GENERATING_DOCUMENTATION)
template <>
struct is_deferred<deferred_noop> : true_type
{
};
#endif // !defined(GENERATING_DOCUMENTATION)
/// Tag type to disambiguate deferred constructors.
struct deferred_init_tag {};
/// Wraps a function object so that it may be used as an element in a deferred
/// composition.
template <typename Function>
class deferred_function
{
public:
/// Constructor.
template <typename F>
BOOST_ASIO_CONSTEXPR explicit deferred_function(
deferred_init_tag, BOOST_ASIO_MOVE_ARG(F) function)
: function_(BOOST_ASIO_MOVE_CAST(F)(function))
{
}
//private:
Function function_;
public:
template <typename... Args>
auto operator()(
BOOST_ASIO_MOVE_ARG(Args)... args) BOOST_ASIO_RVALUE_REF_QUAL
-> decltype(
BOOST_ASIO_MOVE_CAST(Function)(this->function_)(
BOOST_ASIO_MOVE_CAST(Args)(args)...))
{
return BOOST_ASIO_MOVE_CAST(Function)(function_)(
BOOST_ASIO_MOVE_CAST(Args)(args)...);
}
#if defined(BOOST_ASIO_HAS_REF_QUALIFIED_FUNCTIONS)
template <typename... Args>
auto operator()(
BOOST_ASIO_MOVE_ARG(Args)... args) const &
-> decltype(Function(function_)(BOOST_ASIO_MOVE_CAST(Args)(args)...))
{
return Function(function_)(BOOST_ASIO_MOVE_CAST(Args)(args)...);
}
#endif // defined(BOOST_ASIO_HAS_REF_QUALIFIED_FUNCTIONS)
};
#if !defined(GENERATING_DOCUMENTATION)
template <typename Function>
struct is_deferred<deferred_function<Function> > : true_type
{
};
#endif // !defined(GENERATING_DOCUMENTATION)
/// Encapsulates deferred values.
template <typename... Values>
class BOOST_ASIO_NODISCARD deferred_values
{
private:
std::tuple<Values...> values_;
struct initiate
{
template <typename Handler, typename... V>
void operator()(Handler handler, BOOST_ASIO_MOVE_ARG(V)... values)
{
BOOST_ASIO_MOVE_OR_LVALUE(Handler)(handler)(
BOOST_ASIO_MOVE_CAST(V)(values)...);
}
};
template <typename CompletionToken, std::size_t... I>
auto invoke_helper(
BOOST_ASIO_MOVE_ARG(CompletionToken) token,
detail::index_sequence<I...>)
-> decltype(
boost::asio::async_initiate<CompletionToken, void(Values...)>(
initiate(), token,
std::get<I>(
BOOST_ASIO_MOVE_CAST(std::tuple<Values...>)(this->values_))...))
{
return boost::asio::async_initiate<CompletionToken, void(Values...)>(
initiate(), token,
std::get<I>(BOOST_ASIO_MOVE_CAST(std::tuple<Values...>)(values_))...);
}
#if defined(BOOST_ASIO_HAS_REF_QUALIFIED_FUNCTIONS)
template <typename CompletionToken, std::size_t... I>
auto const_invoke_helper(
BOOST_ASIO_MOVE_ARG(CompletionToken) token,
detail::index_sequence<I...>)
-> decltype(
boost::asio::async_initiate<CompletionToken, void(Values...)>(
initiate(), token, std::get<I>(values_)...))
{
return boost::asio::async_initiate<CompletionToken, void(Values...)>(
initiate(), token, std::get<I>(values_)...);
}
#endif // defined(BOOST_ASIO_HAS_REF_QUALIFIED_FUNCTIONS)
public:
/// Construct a deferred asynchronous operation from the arguments to an
/// initiation function object.
template <typename... V>
BOOST_ASIO_CONSTEXPR explicit deferred_values(
deferred_init_tag, BOOST_ASIO_MOVE_ARG(V)... values)
: values_(BOOST_ASIO_MOVE_CAST(V)(values)...)
{
}
/// Initiate the deferred operation using the supplied completion token.
template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void(Values...)) CompletionToken>
auto operator()(
BOOST_ASIO_MOVE_ARG(CompletionToken) token) BOOST_ASIO_RVALUE_REF_QUAL
-> decltype(
this->invoke_helper(
BOOST_ASIO_MOVE_CAST(CompletionToken)(token),
detail::index_sequence_for<Values...>()))
{
return this->invoke_helper(
BOOST_ASIO_MOVE_CAST(CompletionToken)(token),
detail::index_sequence_for<Values...>());
}
#if defined(BOOST_ASIO_HAS_REF_QUALIFIED_FUNCTIONS)
template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void(Values...)) CompletionToken>
auto operator()(
BOOST_ASIO_MOVE_ARG(CompletionToken) token) const &
-> decltype(
this->const_invoke_helper(
BOOST_ASIO_MOVE_CAST(CompletionToken)(token),
detail::index_sequence_for<Values...>()))
{
return this->const_invoke_helper(
BOOST_ASIO_MOVE_CAST(CompletionToken)(token),
detail::index_sequence_for<Values...>());
}
#endif // defined(BOOST_ASIO_HAS_REF_QUALIFIED_FUNCTIONS)
};
#if !defined(GENERATING_DOCUMENTATION)
template <typename... Values>
struct is_deferred<deferred_values<Values...> > : true_type
{
};
#endif // !defined(GENERATING_DOCUMENTATION)
/// Encapsulates a deferred asynchronous operation.
template <typename Signature, typename Initiation, typename... InitArgs>
class BOOST_ASIO_NODISCARD deferred_async_operation
{
private:
typedef typename decay<Initiation>::type initiation_t;
initiation_t initiation_;
typedef std::tuple<typename decay<InitArgs>::type...> init_args_t;
init_args_t init_args_;
template <typename CompletionToken, std::size_t... I>
auto invoke_helper(
BOOST_ASIO_MOVE_ARG(CompletionToken) token,
detail::index_sequence<I...>)
-> decltype(
boost::asio::async_initiate<CompletionToken, Signature>(
BOOST_ASIO_MOVE_CAST(initiation_t)(initiation_), token,
std::get<I>(BOOST_ASIO_MOVE_CAST(init_args_t)(init_args_))...))
{
return boost::asio::async_initiate<CompletionToken, Signature>(
BOOST_ASIO_MOVE_CAST(initiation_t)(initiation_), token,
std::get<I>(BOOST_ASIO_MOVE_CAST(init_args_t)(init_args_))...);
}
#if defined(BOOST_ASIO_HAS_REF_QUALIFIED_FUNCTIONS)
template <typename CompletionToken, std::size_t... I>
auto const_invoke_helper(
BOOST_ASIO_MOVE_ARG(CompletionToken) token,
detail::index_sequence<I...>) const &
-> decltype(
boost::asio::async_initiate<CompletionToken, Signature>(
initiation_t(initiation_), token, std::get<I>(init_args_)...))
{
return boost::asio::async_initiate<CompletionToken, Signature>(
initiation_t(initiation_), token, std::get<I>(init_args_)...);
}
#endif // defined(BOOST_ASIO_HAS_REF_QUALIFIED_FUNCTIONS)
public:
/// Construct a deferred asynchronous operation from the arguments to an
/// initiation function object.
template <typename I, typename... A>
BOOST_ASIO_CONSTEXPR explicit deferred_async_operation(
deferred_init_tag, BOOST_ASIO_MOVE_ARG(I) initiation,
BOOST_ASIO_MOVE_ARG(A)... init_args)
: initiation_(BOOST_ASIO_MOVE_CAST(I)(initiation)),
init_args_(BOOST_ASIO_MOVE_CAST(A)(init_args)...)
{
}
/// Initiate the asynchronous operation using the supplied completion token.
template <BOOST_ASIO_COMPLETION_TOKEN_FOR(Signature) CompletionToken>
auto operator()(
BOOST_ASIO_MOVE_ARG(CompletionToken) token) BOOST_ASIO_RVALUE_REF_QUAL
-> decltype(
this->invoke_helper(
BOOST_ASIO_MOVE_CAST(CompletionToken)(token),
detail::index_sequence_for<InitArgs...>()))
{
return this->invoke_helper(
BOOST_ASIO_MOVE_CAST(CompletionToken)(token),
detail::index_sequence_for<InitArgs...>());
}
#if defined(BOOST_ASIO_HAS_REF_QUALIFIED_FUNCTIONS)
template <BOOST_ASIO_COMPLETION_TOKEN_FOR(Signature) CompletionToken>
auto operator()(
BOOST_ASIO_MOVE_ARG(CompletionToken) token) const &
-> decltype(
this->const_invoke_helper(
BOOST_ASIO_MOVE_CAST(CompletionToken)(token),
detail::index_sequence_for<InitArgs...>()))
{
return this->const_invoke_helper(
BOOST_ASIO_MOVE_CAST(CompletionToken)(token),
detail::index_sequence_for<InitArgs...>());
}
#endif // defined(BOOST_ASIO_HAS_REF_QUALIFIED_FUNCTIONS)
};
#if !defined(GENERATING_DOCUMENTATION)
template <typename Signature, typename Initiation, typename... InitArgs>
struct is_deferred<
deferred_async_operation<Signature, Initiation, InitArgs...> > : true_type
{
};
#endif // !defined(GENERATING_DOCUMENTATION)
/// Defines a link between two consecutive operations in a sequence.
template <typename Head, typename Tail>
class BOOST_ASIO_NODISCARD deferred_sequence
{
private:
typedef typename detail::deferred_sequence_signature<
typename completion_signature_of<Head>::type, Tail>::type
signature;
struct initiate
{
template <typename Handler>
void operator()(BOOST_ASIO_MOVE_ARG(Handler) handler,
Head head, BOOST_ASIO_MOVE_ARG(Tail) tail)
{
BOOST_ASIO_MOVE_OR_LVALUE(Head)(head)(
detail::deferred_sequence_handler<
typename decay<Handler>::type,
typename decay<Tail>::type>(
BOOST_ASIO_MOVE_CAST(Handler)(handler),
BOOST_ASIO_MOVE_CAST(Tail)(tail)));
}
};
Head head_;
Tail tail_;
public:
template <typename H, typename T>
BOOST_ASIO_CONSTEXPR explicit deferred_sequence(deferred_init_tag,
BOOST_ASIO_MOVE_ARG(H) head, BOOST_ASIO_MOVE_ARG(T) tail)
: head_(BOOST_ASIO_MOVE_CAST(H)(head)),
tail_(BOOST_ASIO_MOVE_CAST(T)(tail))
{
}
template <BOOST_ASIO_COMPLETION_TOKEN_FOR(signature) CompletionToken>
auto operator()(
BOOST_ASIO_MOVE_ARG(CompletionToken) token) BOOST_ASIO_RVALUE_REF_QUAL
-> decltype(
boost::asio::async_initiate<CompletionToken, signature>(
declval<initiate>(), token,
BOOST_ASIO_MOVE_OR_LVALUE(Head)(this->head_),
BOOST_ASIO_MOVE_OR_LVALUE(Tail)(this->tail_)))
{
return boost::asio::async_initiate<CompletionToken, signature>(
initiate(), token,
BOOST_ASIO_MOVE_OR_LVALUE(Head)(head_),
BOOST_ASIO_MOVE_OR_LVALUE(Tail)(tail_));
}
#if defined(BOOST_ASIO_HAS_REF_QUALIFIED_FUNCTIONS)
template <BOOST_ASIO_COMPLETION_TOKEN_FOR(signature) CompletionToken>
auto operator()(
BOOST_ASIO_MOVE_ARG(CompletionToken) token) const &
-> decltype(
boost::asio::async_initiate<CompletionToken, signature>(
initiate(), token, head_, tail_))
{
return boost::asio::async_initiate<CompletionToken, signature>(
initiate(), token, head_, tail_);
}
#endif // defined(BOOST_ASIO_HAS_REF_QUALIFIED_FUNCTIONS)
};
#if !defined(GENERATING_DOCUMENTATION)
template <typename Head, typename Tail>
struct is_deferred<deferred_sequence<Head, Tail> > : true_type
{
};
#endif // !defined(GENERATING_DOCUMENTATION)
/// Used to represent a deferred conditional branch.
template <typename OnTrue = deferred_noop,
typename OnFalse = deferred_noop>
class BOOST_ASIO_NODISCARD deferred_conditional
{
private:
template <typename T, typename F> friend class deferred_conditional;
// Helper constructor.
template <typename T, typename F>
explicit deferred_conditional(bool b, BOOST_ASIO_MOVE_ARG(T) on_true,
BOOST_ASIO_MOVE_ARG(F) on_false)
: on_true_(BOOST_ASIO_MOVE_CAST(T)(on_true)),
on_false_(BOOST_ASIO_MOVE_CAST(F)(on_false)),
bool_(b)
{
}
OnTrue on_true_;
OnFalse on_false_;
bool bool_;
public:
/// Construct a deferred conditional with the value to determine which branch
/// will be executed.
BOOST_ASIO_CONSTEXPR explicit deferred_conditional(bool b)
: on_true_(),
on_false_(),
bool_(b)
{
}
/// Invoke the conditional branch bsaed on the stored alue.
template <typename... Args>
auto operator()(BOOST_ASIO_MOVE_ARG(Args)... args) BOOST_ASIO_RVALUE_REF_QUAL
-> decltype(
BOOST_ASIO_MOVE_OR_LVALUE(OnTrue)(on_true_)(
BOOST_ASIO_MOVE_CAST(Args)(args)...))
{
if (bool_)
{
return BOOST_ASIO_MOVE_OR_LVALUE(OnTrue)(on_true_)(
BOOST_ASIO_MOVE_CAST(Args)(args)...);
}
else
{
return BOOST_ASIO_MOVE_OR_LVALUE(OnFalse)(on_false_)(
BOOST_ASIO_MOVE_CAST(Args)(args)...);
}
}
#if defined(BOOST_ASIO_HAS_REF_QUALIFIED_FUNCTIONS)
template <typename... Args>
auto operator()(BOOST_ASIO_MOVE_ARG(Args)... args) const &
-> decltype(on_true_(BOOST_ASIO_MOVE_CAST(Args)(args)...))
{
if (bool_)
{
return on_true_(BOOST_ASIO_MOVE_CAST(Args)(args)...);
}
else
{
return on_false_(BOOST_ASIO_MOVE_CAST(Args)(args)...);
}
}
#endif // defined(BOOST_ASIO_HAS_REF_QUALIFIED_FUNCTIONS)
/// Set the true branch of the conditional.
template <typename T>
deferred_conditional<T, OnFalse> then(T on_true,
typename constraint<
is_deferred<T>::value
>::type* = 0,
typename constraint<
is_same<
typename conditional<true, OnTrue, T>::type,
deferred_noop
>::value
>::type* = 0) BOOST_ASIO_RVALUE_REF_QUAL
{
return deferred_conditional<T, OnFalse>(
bool_, BOOST_ASIO_MOVE_CAST(T)(on_true),
BOOST_ASIO_MOVE_CAST(OnFalse)(on_false_));
}
/// Set the false branch of the conditional.
template <typename T>
deferred_conditional<OnTrue, T> otherwise(T on_false,
typename constraint<
is_deferred<T>::value
>::type* = 0,
typename constraint<
!is_same<
typename conditional<true, OnTrue, T>::type,
deferred_noop
>::value
>::type* = 0,
typename constraint<
is_same<
typename conditional<true, OnFalse, T>::type,
deferred_noop
>::value
>::type* = 0) BOOST_ASIO_RVALUE_REF_QUAL
{
return deferred_conditional<OnTrue, T>(
bool_, BOOST_ASIO_MOVE_CAST(OnTrue)(on_true_),
BOOST_ASIO_MOVE_CAST(T)(on_false));
}
};
#if !defined(GENERATING_DOCUMENTATION)
template <typename OnTrue, typename OnFalse>
struct is_deferred<deferred_conditional<OnTrue, OnFalse> > : true_type
{
};
#endif // !defined(GENERATING_DOCUMENTATION)
/// Class used to specify that an asynchronous operation should return a
/// function object to lazily launch the operation.
/**
* The deferred_t class is used to indicate that an asynchronous operation
* should return a function object which is itself an initiation function. A
* deferred_t object may be passed as a completion token to an asynchronous
* operation, typically using the special value @c boost::asio::deferred. For
* example:
*
* @code auto my_deferred_op
* = my_socket.async_read_some(my_buffer,
* boost::asio::deferred); @endcode
*
* The initiating function (async_read_some in the above example) returns a
* function object that will lazily initiate the operation.
*/
class deferred_t
{
public:
/// Default constructor.
BOOST_ASIO_CONSTEXPR deferred_t()
{
}
/// Adapts an executor to add the @c deferred_t completion token as the
/// default.
template <typename InnerExecutor>
struct executor_with_default : InnerExecutor
{
/// Specify @c deferred_t as the default completion token type.
typedef deferred_t default_completion_token_type;
/// Construct the adapted executor from the inner executor type.
template <typename InnerExecutor1>
executor_with_default(const InnerExecutor1& ex,
typename constraint<
conditional<
!is_same<InnerExecutor1, executor_with_default>::value,
is_convertible<InnerExecutor1, InnerExecutor>,
false_type
>::type::value
>::type = 0) BOOST_ASIO_NOEXCEPT
: InnerExecutor(ex)
{
}
};
/// Type alias to adapt an I/O object to use @c deferred_t as its
/// default completion token type.
#if defined(BOOST_ASIO_HAS_ALIAS_TEMPLATES) \
|| defined(GENERATING_DOCUMENTATION)
template <typename T>
using as_default_on_t = typename T::template rebind_executor<
executor_with_default<typename T::executor_type> >::other;
#endif // defined(BOOST_ASIO_HAS_ALIAS_TEMPLATES)
// || defined(GENERATING_DOCUMENTATION)
/// Function helper to adapt an I/O object to use @c deferred_t as its
/// default completion token type.
template <typename T>
static typename decay<T>::type::template rebind_executor<
executor_with_default<typename decay<T>::type::executor_type>
>::other
as_default_on(BOOST_ASIO_MOVE_ARG(T) object)
{
return typename decay<T>::type::template rebind_executor<
executor_with_default<typename decay<T>::type::executor_type>
>::other(BOOST_ASIO_MOVE_CAST(T)(object));
}
/// Creates a new deferred from a function.
template <typename Function>
typename constraint<
!is_deferred<typename decay<Function>::type>::value,
deferred_function<typename decay<Function>::type>
>::type operator()(BOOST_ASIO_MOVE_ARG(Function) function) const
{
return deferred_function<typename decay<Function>::type>(
deferred_init_tag{}, BOOST_ASIO_MOVE_CAST(Function)(function));
}
/// Passes through anything that is already deferred.
template <typename T>
typename constraint<
is_deferred<typename decay<T>::type>::value,
typename decay<T>::type
>::type operator()(BOOST_ASIO_MOVE_ARG(T) t) const
{
return BOOST_ASIO_MOVE_CAST(T)(t);
}
/// Returns a deferred operation that returns the provided values.
template <typename... Args>
static BOOST_ASIO_CONSTEXPR deferred_values<typename decay<Args>::type...>
values(BOOST_ASIO_MOVE_ARG(Args)... args)
{
return deferred_values<typename decay<Args>::type...>(
deferred_init_tag{}, BOOST_ASIO_MOVE_CAST(Args)(args)...);
}
/// Creates a conditional object for branching deferred operations.
static BOOST_ASIO_CONSTEXPR deferred_conditional<> when(bool b)
{
return deferred_conditional<>(b);
}
};
/// Pipe operator used to chain deferred operations.
template <typename Head, typename Tail>
inline auto operator|(Head head, BOOST_ASIO_MOVE_ARG(Tail) tail)
-> typename constraint<
is_deferred<Head>::value,
decltype(BOOST_ASIO_MOVE_OR_LVALUE(Head)(head)(
BOOST_ASIO_MOVE_CAST(Tail)(tail)))
>::type
{
return BOOST_ASIO_MOVE_OR_LVALUE(Head)(head)(
BOOST_ASIO_MOVE_CAST(Tail)(tail));
}
/// A @ref completion_token object used to specify that an asynchronous
/// operation should return a function object to lazily launch the operation.
/**
* See the documentation for boost::asio::deferred_t for a usage example.
*/
#if defined(BOOST_ASIO_HAS_CONSTEXPR) || defined(GENERATING_DOCUMENTATION)
constexpr deferred_t deferred;
#elif defined(BOOST_ASIO_MSVC)
__declspec(selectany) deferred_t deferred;
#endif
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#include <boost/asio/impl/deferred.hpp>
#endif // (defined(BOOST_ASIO_HAS_STD_TUPLE)
// && defined(BOOST_ASIO_HAS_DECLTYPE))
// && defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES))
// || defined(GENERATING_DOCUMENTATION)
#endif // BOOST_ASIO_DEFERRED_HPP