Clementine
bind_handler.hpp
1 //
2 // detail/bind_handler.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 ASIO_DETAIL_BIND_HANDLER_HPP
12 #define ASIO_DETAIL_BIND_HANDLER_HPP
13 
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17 
18 #include "asio/detail/config.hpp"
19 #include "asio/associated_allocator.hpp"
20 #include "asio/associated_executor.hpp"
21 #include "asio/detail/handler_alloc_helpers.hpp"
22 #include "asio/detail/handler_cont_helpers.hpp"
23 #include "asio/detail/handler_invoke_helpers.hpp"
24 #include "asio/detail/type_traits.hpp"
25 
26 #include "asio/detail/push_options.hpp"
27 
28 namespace asio {
29 namespace detail {
30 
31 template <typename Handler, typename Arg1>
32 class binder1
33 {
34 public:
35  template <typename T>
36  binder1(int, ASIO_MOVE_ARG(T) handler, const Arg1& arg1)
37  : handler_(ASIO_MOVE_CAST(T)(handler)),
38  arg1_(arg1)
39  {
40  }
41 
42  binder1(Handler& handler, const Arg1& arg1)
43  : handler_(ASIO_MOVE_CAST(Handler)(handler)),
44  arg1_(arg1)
45  {
46  }
47 
48 #if defined(ASIO_HAS_MOVE)
49  binder1(const binder1& other)
50  : handler_(other.handler_),
51  arg1_(other.arg1_)
52  {
53  }
54 
55  binder1(binder1&& other)
56  : handler_(ASIO_MOVE_CAST(Handler)(other.handler_)),
57  arg1_(ASIO_MOVE_CAST(Arg1)(other.arg1_))
58  {
59  }
60 #endif // defined(ASIO_HAS_MOVE)
61 
62  void operator()()
63  {
64  handler_(static_cast<const Arg1&>(arg1_));
65  }
66 
67  void operator()() const
68  {
69  handler_(arg1_);
70  }
71 
72 //private:
73  Handler handler_;
74  Arg1 arg1_;
75 };
76 
77 template <typename Handler, typename Arg1>
78 inline asio_handler_allocate_is_deprecated
79 asio_handler_allocate(std::size_t size,
80  binder1<Handler, Arg1>* this_handler)
81 {
82 #if defined(ASIO_NO_DEPRECATED)
83  asio_handler_alloc_helpers::allocate(size, this_handler->handler_);
84  return asio_handler_allocate_is_no_longer_used();
85 #else // defined(ASIO_NO_DEPRECATED)
86  return asio_handler_alloc_helpers::allocate(
87  size, this_handler->handler_);
88 #endif // defined(ASIO_NO_DEPRECATED)
89 }
90 
91 template <typename Handler, typename Arg1>
92 inline asio_handler_deallocate_is_deprecated
93 asio_handler_deallocate(void* pointer, std::size_t size,
94  binder1<Handler, Arg1>* this_handler)
95 {
96  asio_handler_alloc_helpers::deallocate(
97  pointer, size, this_handler->handler_);
98 #if defined(ASIO_NO_DEPRECATED)
99  return asio_handler_deallocate_is_no_longer_used();
100 #endif // defined(ASIO_NO_DEPRECATED)
101 }
102 
103 template <typename Handler, typename Arg1>
104 inline bool asio_handler_is_continuation(
105  binder1<Handler, Arg1>* this_handler)
106 {
107  return asio_handler_cont_helpers::is_continuation(
108  this_handler->handler_);
109 }
110 
111 template <typename Function, typename Handler, typename Arg1>
112 inline asio_handler_invoke_is_deprecated
113 asio_handler_invoke(Function& function,
114  binder1<Handler, Arg1>* this_handler)
115 {
116  asio_handler_invoke_helpers::invoke(
117  function, this_handler->handler_);
118 #if defined(ASIO_NO_DEPRECATED)
119  return asio_handler_invoke_is_no_longer_used();
120 #endif // defined(ASIO_NO_DEPRECATED)
121 }
122 
123 template <typename Function, typename Handler, typename Arg1>
124 inline asio_handler_invoke_is_deprecated
125 asio_handler_invoke(const Function& function,
126  binder1<Handler, Arg1>* this_handler)
127 {
128  asio_handler_invoke_helpers::invoke(
129  function, this_handler->handler_);
130 #if defined(ASIO_NO_DEPRECATED)
131  return asio_handler_invoke_is_no_longer_used();
132 #endif // defined(ASIO_NO_DEPRECATED)
133 }
134 
135 template <typename Handler, typename Arg1>
136 inline binder1<typename decay<Handler>::type, Arg1> bind_handler(
137  ASIO_MOVE_ARG(Handler) handler, const Arg1& arg1)
138 {
140  ASIO_MOVE_CAST(Handler)(handler), arg1);
141 }
142 
143 template <typename Handler, typename Arg1, typename Arg2>
144 class binder2
145 {
146 public:
147  template <typename T>
148  binder2(int, ASIO_MOVE_ARG(T) handler,
149  const Arg1& arg1, const Arg2& arg2)
150  : handler_(ASIO_MOVE_CAST(T)(handler)),
151  arg1_(arg1),
152  arg2_(arg2)
153  {
154  }
155 
156  binder2(Handler& handler, const Arg1& arg1, const Arg2& arg2)
157  : handler_(ASIO_MOVE_CAST(Handler)(handler)),
158  arg1_(arg1),
159  arg2_(arg2)
160  {
161  }
162 
163 #if defined(ASIO_HAS_MOVE)
164  binder2(const binder2& other)
165  : handler_(other.handler_),
166  arg1_(other.arg1_),
167  arg2_(other.arg2_)
168  {
169  }
170 
171  binder2(binder2&& other)
172  : handler_(ASIO_MOVE_CAST(Handler)(other.handler_)),
173  arg1_(ASIO_MOVE_CAST(Arg1)(other.arg1_)),
174  arg2_(ASIO_MOVE_CAST(Arg2)(other.arg2_))
175  {
176  }
177 #endif // defined(ASIO_HAS_MOVE)
178 
179  void operator()()
180  {
181  handler_(static_cast<const Arg1&>(arg1_),
182  static_cast<const Arg2&>(arg2_));
183  }
184 
185  void operator()() const
186  {
187  handler_(arg1_, arg2_);
188  }
189 
190 //private:
191  Handler handler_;
192  Arg1 arg1_;
193  Arg2 arg2_;
194 };
195 
196 template <typename Handler, typename Arg1, typename Arg2>
197 inline asio_handler_allocate_is_deprecated
198 asio_handler_allocate(std::size_t size,
199  binder2<Handler, Arg1, Arg2>* this_handler)
200 {
201 #if defined(ASIO_NO_DEPRECATED)
202  asio_handler_alloc_helpers::allocate(size, this_handler->handler_);
203  return asio_handler_allocate_is_no_longer_used();
204 #else // defined(ASIO_NO_DEPRECATED)
205  return asio_handler_alloc_helpers::allocate(
206  size, this_handler->handler_);
207 #endif // defined(ASIO_NO_DEPRECATED)
208 }
209 
210 template <typename Handler, typename Arg1, typename Arg2>
211 inline asio_handler_deallocate_is_deprecated
212 asio_handler_deallocate(void* pointer, std::size_t size,
213  binder2<Handler, Arg1, Arg2>* this_handler)
214 {
215  asio_handler_alloc_helpers::deallocate(
216  pointer, size, this_handler->handler_);
217 #if defined(ASIO_NO_DEPRECATED)
218  return asio_handler_deallocate_is_no_longer_used();
219 #endif // defined(ASIO_NO_DEPRECATED)
220 }
221 
222 template <typename Handler, typename Arg1, typename Arg2>
223 inline bool asio_handler_is_continuation(
224  binder2<Handler, Arg1, Arg2>* this_handler)
225 {
226  return asio_handler_cont_helpers::is_continuation(
227  this_handler->handler_);
228 }
229 
230 template <typename Function, typename Handler, typename Arg1, typename Arg2>
231 inline asio_handler_invoke_is_deprecated
232 asio_handler_invoke(Function& function,
233  binder2<Handler, Arg1, Arg2>* this_handler)
234 {
235  asio_handler_invoke_helpers::invoke(
236  function, this_handler->handler_);
237 #if defined(ASIO_NO_DEPRECATED)
238  return asio_handler_invoke_is_no_longer_used();
239 #endif // defined(ASIO_NO_DEPRECATED)
240 }
241 
242 template <typename Function, typename Handler, typename Arg1, typename Arg2>
243 inline asio_handler_invoke_is_deprecated
244 asio_handler_invoke(const Function& function,
245  binder2<Handler, Arg1, Arg2>* this_handler)
246 {
247  asio_handler_invoke_helpers::invoke(
248  function, this_handler->handler_);
249 #if defined(ASIO_NO_DEPRECATED)
250  return asio_handler_invoke_is_no_longer_used();
251 #endif // defined(ASIO_NO_DEPRECATED)
252 }
253 
254 template <typename Handler, typename Arg1, typename Arg2>
255 inline binder2<typename decay<Handler>::type, Arg1, Arg2> bind_handler(
256  ASIO_MOVE_ARG(Handler) handler, const Arg1& arg1, const Arg2& arg2)
257 {
258  return binder2<typename decay<Handler>::type, Arg1, Arg2>(0,
259  ASIO_MOVE_CAST(Handler)(handler), arg1, arg2);
260 }
261 
262 template <typename Handler, typename Arg1, typename Arg2, typename Arg3>
263 class binder3
264 {
265 public:
266  template <typename T>
267  binder3(int, ASIO_MOVE_ARG(T) handler, const Arg1& arg1,
268  const Arg2& arg2, const Arg3& arg3)
269  : handler_(ASIO_MOVE_CAST(T)(handler)),
270  arg1_(arg1),
271  arg2_(arg2),
272  arg3_(arg3)
273  {
274  }
275 
276  binder3(Handler& handler, const Arg1& arg1,
277  const Arg2& arg2, const Arg3& arg3)
278  : handler_(ASIO_MOVE_CAST(Handler)(handler)),
279  arg1_(arg1),
280  arg2_(arg2),
281  arg3_(arg3)
282  {
283  }
284 
285 #if defined(ASIO_HAS_MOVE)
286  binder3(const binder3& other)
287  : handler_(other.handler_),
288  arg1_(other.arg1_),
289  arg2_(other.arg2_),
290  arg3_(other.arg3_)
291  {
292  }
293 
294  binder3(binder3&& other)
295  : handler_(ASIO_MOVE_CAST(Handler)(other.handler_)),
296  arg1_(ASIO_MOVE_CAST(Arg1)(other.arg1_)),
297  arg2_(ASIO_MOVE_CAST(Arg2)(other.arg2_)),
298  arg3_(ASIO_MOVE_CAST(Arg3)(other.arg3_))
299  {
300  }
301 #endif // defined(ASIO_HAS_MOVE)
302 
303  void operator()()
304  {
305  handler_(static_cast<const Arg1&>(arg1_),
306  static_cast<const Arg2&>(arg2_), static_cast<const Arg3&>(arg3_));
307  }
308 
309  void operator()() const
310  {
311  handler_(arg1_, arg2_, arg3_);
312  }
313 
314 //private:
315  Handler handler_;
316  Arg1 arg1_;
317  Arg2 arg2_;
318  Arg3 arg3_;
319 };
320 
321 template <typename Handler, typename Arg1, typename Arg2, typename Arg3>
322 inline asio_handler_allocate_is_deprecated
323 asio_handler_allocate(std::size_t size,
325 {
326 #if defined(ASIO_NO_DEPRECATED)
327  asio_handler_alloc_helpers::allocate(size, this_handler->handler_);
328  return asio_handler_allocate_is_no_longer_used();
329 #else // defined(ASIO_NO_DEPRECATED)
330  return asio_handler_alloc_helpers::allocate(
331  size, this_handler->handler_);
332 #endif // defined(ASIO_NO_DEPRECATED)
333 }
334 
335 template <typename Handler, typename Arg1, typename Arg2, typename Arg3>
336 inline asio_handler_deallocate_is_deprecated
337 asio_handler_deallocate(void* pointer, std::size_t size,
339 {
340  asio_handler_alloc_helpers::deallocate(
341  pointer, size, this_handler->handler_);
342 #if defined(ASIO_NO_DEPRECATED)
343  return asio_handler_deallocate_is_no_longer_used();
344 #endif // defined(ASIO_NO_DEPRECATED)
345 }
346 
347 template <typename Handler, typename Arg1, typename Arg2, typename Arg3>
348 inline bool asio_handler_is_continuation(
350 {
351  return asio_handler_cont_helpers::is_continuation(
352  this_handler->handler_);
353 }
354 
355 template <typename Function, typename Handler,
356  typename Arg1, typename Arg2, typename Arg3>
357 inline asio_handler_invoke_is_deprecated
358 asio_handler_invoke(Function& function,
360 {
361  asio_handler_invoke_helpers::invoke(
362  function, this_handler->handler_);
363 #if defined(ASIO_NO_DEPRECATED)
364  return asio_handler_invoke_is_no_longer_used();
365 #endif // defined(ASIO_NO_DEPRECATED)
366 }
367 
368 template <typename Function, typename Handler,
369  typename Arg1, typename Arg2, typename Arg3>
370 inline asio_handler_invoke_is_deprecated
371 asio_handler_invoke(const Function& function,
373 {
374  asio_handler_invoke_helpers::invoke(
375  function, this_handler->handler_);
376 #if defined(ASIO_NO_DEPRECATED)
377  return asio_handler_invoke_is_no_longer_used();
378 #endif // defined(ASIO_NO_DEPRECATED)
379 }
380 
381 template <typename Handler, typename Arg1, typename Arg2, typename Arg3>
382 inline binder3<typename decay<Handler>::type, Arg1, Arg2, Arg3> bind_handler(
383  ASIO_MOVE_ARG(Handler) handler, const Arg1& arg1, const Arg2& arg2,
384  const Arg3& arg3)
385 {
386  return binder3<typename decay<Handler>::type, Arg1, Arg2, Arg3>(0,
387  ASIO_MOVE_CAST(Handler)(handler), arg1, arg2, arg3);
388 }
389 
390 template <typename Handler, typename Arg1,
391  typename Arg2, typename Arg3, typename Arg4>
392 class binder4
393 {
394 public:
395  template <typename T>
396  binder4(int, ASIO_MOVE_ARG(T) handler, const Arg1& arg1,
397  const Arg2& arg2, const Arg3& arg3, const Arg4& arg4)
398  : handler_(ASIO_MOVE_CAST(T)(handler)),
399  arg1_(arg1),
400  arg2_(arg2),
401  arg3_(arg3),
402  arg4_(arg4)
403  {
404  }
405 
406  binder4(Handler& handler, const Arg1& arg1,
407  const Arg2& arg2, const Arg3& arg3, const Arg4& arg4)
408  : handler_(ASIO_MOVE_CAST(Handler)(handler)),
409  arg1_(arg1),
410  arg2_(arg2),
411  arg3_(arg3),
412  arg4_(arg4)
413  {
414  }
415 
416 #if defined(ASIO_HAS_MOVE)
417  binder4(const binder4& other)
418  : handler_(other.handler_),
419  arg1_(other.arg1_),
420  arg2_(other.arg2_),
421  arg3_(other.arg3_),
422  arg4_(other.arg4_)
423  {
424  }
425 
426  binder4(binder4&& other)
427  : handler_(ASIO_MOVE_CAST(Handler)(other.handler_)),
428  arg1_(ASIO_MOVE_CAST(Arg1)(other.arg1_)),
429  arg2_(ASIO_MOVE_CAST(Arg2)(other.arg2_)),
430  arg3_(ASIO_MOVE_CAST(Arg3)(other.arg3_)),
431  arg4_(ASIO_MOVE_CAST(Arg4)(other.arg4_))
432  {
433  }
434 #endif // defined(ASIO_HAS_MOVE)
435 
436  void operator()()
437  {
438  handler_(static_cast<const Arg1&>(arg1_),
439  static_cast<const Arg2&>(arg2_), static_cast<const Arg3&>(arg3_),
440  static_cast<const Arg4&>(arg4_));
441  }
442 
443  void operator()() const
444  {
445  handler_(arg1_, arg2_, arg3_, arg4_);
446  }
447 
448 //private:
449  Handler handler_;
450  Arg1 arg1_;
451  Arg2 arg2_;
452  Arg3 arg3_;
453  Arg4 arg4_;
454 };
455 
456 template <typename Handler, typename Arg1,
457  typename Arg2, typename Arg3, typename Arg4>
458 inline asio_handler_allocate_is_deprecated
459 asio_handler_allocate(std::size_t size,
461 {
462 #if defined(ASIO_NO_DEPRECATED)
463  asio_handler_alloc_helpers::allocate(size, this_handler->handler_);
464  return asio_handler_allocate_is_no_longer_used();
465 #else // defined(ASIO_NO_DEPRECATED)
466  return asio_handler_alloc_helpers::allocate(
467  size, this_handler->handler_);
468 #endif // defined(ASIO_NO_DEPRECATED)
469 }
470 
471 template <typename Handler, typename Arg1,
472  typename Arg2, typename Arg3, typename Arg4>
473 inline asio_handler_deallocate_is_deprecated
474 asio_handler_deallocate(void* pointer, std::size_t size,
476 {
477  asio_handler_alloc_helpers::deallocate(
478  pointer, size, this_handler->handler_);
479 #if defined(ASIO_NO_DEPRECATED)
480  return asio_handler_deallocate_is_no_longer_used();
481 #endif // defined(ASIO_NO_DEPRECATED)
482 }
483 
484 template <typename Handler, typename Arg1,
485  typename Arg2, typename Arg3, typename Arg4>
486 inline bool asio_handler_is_continuation(
488 {
489  return asio_handler_cont_helpers::is_continuation(
490  this_handler->handler_);
491 }
492 
493 template <typename Function, typename Handler, typename Arg1,
494  typename Arg2, typename Arg3, typename Arg4>
495 inline asio_handler_invoke_is_deprecated
496 asio_handler_invoke(Function& function,
498 {
499  asio_handler_invoke_helpers::invoke(
500  function, this_handler->handler_);
501 #if defined(ASIO_NO_DEPRECATED)
502  return asio_handler_invoke_is_no_longer_used();
503 #endif // defined(ASIO_NO_DEPRECATED)
504 }
505 
506 template <typename Function, typename Handler, typename Arg1,
507  typename Arg2, typename Arg3, typename Arg4>
508 inline asio_handler_invoke_is_deprecated
509 asio_handler_invoke(const Function& function,
511 {
512  asio_handler_invoke_helpers::invoke(
513  function, this_handler->handler_);
514 #if defined(ASIO_NO_DEPRECATED)
515  return asio_handler_invoke_is_no_longer_used();
516 #endif // defined(ASIO_NO_DEPRECATED)
517 }
518 
519 template <typename Handler, typename Arg1,
520  typename Arg2, typename Arg3, typename Arg4>
521 inline binder4<typename decay<Handler>::type, Arg1, Arg2, Arg3, Arg4>
522 bind_handler(ASIO_MOVE_ARG(Handler) handler, const Arg1& arg1,
523  const Arg2& arg2, const Arg3& arg3, const Arg4& arg4)
524 {
525  return binder4<typename decay<Handler>::type, Arg1, Arg2, Arg3, Arg4>(0,
526  ASIO_MOVE_CAST(Handler)(handler), arg1, arg2, arg3, arg4);
527 }
528 
529 template <typename Handler, typename Arg1, typename Arg2,
530  typename Arg3, typename Arg4, typename Arg5>
531 class binder5
532 {
533 public:
534  template <typename T>
535  binder5(int, ASIO_MOVE_ARG(T) handler, const Arg1& arg1,
536  const Arg2& arg2, const Arg3& arg3, const Arg4& arg4, const Arg5& arg5)
537  : handler_(ASIO_MOVE_CAST(T)(handler)),
538  arg1_(arg1),
539  arg2_(arg2),
540  arg3_(arg3),
541  arg4_(arg4),
542  arg5_(arg5)
543  {
544  }
545 
546  binder5(Handler& handler, const Arg1& arg1, const Arg2& arg2,
547  const Arg3& arg3, const Arg4& arg4, const Arg5& arg5)
548  : handler_(ASIO_MOVE_CAST(Handler)(handler)),
549  arg1_(arg1),
550  arg2_(arg2),
551  arg3_(arg3),
552  arg4_(arg4),
553  arg5_(arg5)
554  {
555  }
556 
557 #if defined(ASIO_HAS_MOVE)
558  binder5(const binder5& other)
559  : handler_(other.handler_),
560  arg1_(other.arg1_),
561  arg2_(other.arg2_),
562  arg3_(other.arg3_),
563  arg4_(other.arg4_),
564  arg5_(other.arg5_)
565  {
566  }
567 
568  binder5(binder5&& other)
569  : handler_(ASIO_MOVE_CAST(Handler)(other.handler_)),
570  arg1_(ASIO_MOVE_CAST(Arg1)(other.arg1_)),
571  arg2_(ASIO_MOVE_CAST(Arg2)(other.arg2_)),
572  arg3_(ASIO_MOVE_CAST(Arg3)(other.arg3_)),
573  arg4_(ASIO_MOVE_CAST(Arg4)(other.arg4_)),
574  arg5_(ASIO_MOVE_CAST(Arg5)(other.arg5_))
575  {
576  }
577 #endif // defined(ASIO_HAS_MOVE)
578 
579  void operator()()
580  {
581  handler_(static_cast<const Arg1&>(arg1_),
582  static_cast<const Arg2&>(arg2_), static_cast<const Arg3&>(arg3_),
583  static_cast<const Arg4&>(arg4_), static_cast<const Arg5&>(arg5_));
584  }
585 
586  void operator()() const
587  {
588  handler_(arg1_, arg2_, arg3_, arg4_, arg5_);
589  }
590 
591 //private:
592  Handler handler_;
593  Arg1 arg1_;
594  Arg2 arg2_;
595  Arg3 arg3_;
596  Arg4 arg4_;
597  Arg5 arg5_;
598 };
599 
600 template <typename Handler, typename Arg1, typename Arg2,
601  typename Arg3, typename Arg4, typename Arg5>
602 inline asio_handler_allocate_is_deprecated
603 asio_handler_allocate(std::size_t size,
605 {
606 #if defined(ASIO_NO_DEPRECATED)
607  asio_handler_alloc_helpers::allocate(size, this_handler->handler_);
608  return asio_handler_allocate_is_no_longer_used();
609 #else // defined(ASIO_NO_DEPRECATED)
610  return asio_handler_alloc_helpers::allocate(
611  size, this_handler->handler_);
612 #endif // defined(ASIO_NO_DEPRECATED)
613 }
614 
615 template <typename Handler, typename Arg1, typename Arg2,
616  typename Arg3, typename Arg4, typename Arg5>
617 inline asio_handler_deallocate_is_deprecated
618 asio_handler_deallocate(void* pointer, std::size_t size,
620 {
621  asio_handler_alloc_helpers::deallocate(
622  pointer, size, this_handler->handler_);
623 #if defined(ASIO_NO_DEPRECATED)
624  return asio_handler_deallocate_is_no_longer_used();
625 #endif // defined(ASIO_NO_DEPRECATED)
626 }
627 
628 template <typename Handler, typename Arg1, typename Arg2,
629  typename Arg3, typename Arg4, typename Arg5>
630 inline bool asio_handler_is_continuation(
632 {
633  return asio_handler_cont_helpers::is_continuation(
634  this_handler->handler_);
635 }
636 
637 template <typename Function, typename Handler, typename Arg1,
638  typename Arg2, typename Arg3, typename Arg4, typename Arg5>
639 inline asio_handler_invoke_is_deprecated
640 asio_handler_invoke(Function& function,
642 {
643  asio_handler_invoke_helpers::invoke(
644  function, this_handler->handler_);
645 #if defined(ASIO_NO_DEPRECATED)
646  return asio_handler_invoke_is_no_longer_used();
647 #endif // defined(ASIO_NO_DEPRECATED)
648 }
649 
650 template <typename Function, typename Handler, typename Arg1,
651  typename Arg2, typename Arg3, typename Arg4, typename Arg5>
652 inline asio_handler_invoke_is_deprecated
653 asio_handler_invoke(const Function& function,
655 {
656  asio_handler_invoke_helpers::invoke(
657  function, this_handler->handler_);
658 #if defined(ASIO_NO_DEPRECATED)
659  return asio_handler_invoke_is_no_longer_used();
660 #endif // defined(ASIO_NO_DEPRECATED)
661 }
662 
663 template <typename Handler, typename Arg1, typename Arg2,
664  typename Arg3, typename Arg4, typename Arg5>
665 inline binder5<typename decay<Handler>::type, Arg1, Arg2, Arg3, Arg4, Arg5>
666 bind_handler(ASIO_MOVE_ARG(Handler) handler, const Arg1& arg1,
667  const Arg2& arg2, const Arg3& arg3, const Arg4& arg4, const Arg5& arg5)
668 {
669  return binder5<typename decay<Handler>::type, Arg1, Arg2, Arg3, Arg4, Arg5>(0,
670  ASIO_MOVE_CAST(Handler)(handler), arg1, arg2, arg3, arg4, arg5);
671 }
672 
673 #if defined(ASIO_HAS_MOVE)
674 
675 template <typename Handler, typename Arg1>
676 class move_binder1
677 {
678 public:
679  move_binder1(int, ASIO_MOVE_ARG(Handler) handler,
680  ASIO_MOVE_ARG(Arg1) arg1)
681  : handler_(ASIO_MOVE_CAST(Handler)(handler)),
682  arg1_(ASIO_MOVE_CAST(Arg1)(arg1))
683  {
684  }
685 
686  move_binder1(move_binder1&& other)
687  : handler_(ASIO_MOVE_CAST(Handler)(other.handler_)),
688  arg1_(ASIO_MOVE_CAST(Arg1)(other.arg1_))
689  {
690  }
691 
692  void operator()()
693  {
694  handler_(ASIO_MOVE_CAST(Arg1)(arg1_));
695  }
696 
697 //private:
698  Handler handler_;
699  Arg1 arg1_;
700 };
701 
702 template <typename Handler, typename Arg1>
703 inline asio_handler_allocate_is_deprecated
704 asio_handler_allocate(std::size_t size,
705  move_binder1<Handler, Arg1>* this_handler)
706 {
707 #if defined(ASIO_NO_DEPRECATED)
708  asio_handler_alloc_helpers::allocate(size, this_handler->handler_);
709  return asio_handler_allocate_is_no_longer_used();
710 #else // defined(ASIO_NO_DEPRECATED)
711  return asio_handler_alloc_helpers::allocate(
712  size, this_handler->handler_);
713 #endif // defined(ASIO_NO_DEPRECATED)
714 }
715 
716 template <typename Handler, typename Arg1>
717 inline asio_handler_deallocate_is_deprecated
718 asio_handler_deallocate(void* pointer, std::size_t size,
719  move_binder1<Handler, Arg1>* this_handler)
720 {
721  asio_handler_alloc_helpers::deallocate(
722  pointer, size, this_handler->handler_);
723 #if defined(ASIO_NO_DEPRECATED)
724  return asio_handler_deallocate_is_no_longer_used();
725 #endif // defined(ASIO_NO_DEPRECATED)
726 }
727 
728 template <typename Handler, typename Arg1>
729 inline bool asio_handler_is_continuation(
730  move_binder1<Handler, Arg1>* this_handler)
731 {
732  return asio_handler_cont_helpers::is_continuation(
733  this_handler->handler_);
734 }
735 
736 template <typename Function, typename Handler, typename Arg1>
737 inline asio_handler_invoke_is_deprecated
738 asio_handler_invoke(ASIO_MOVE_ARG(Function) function,
739  move_binder1<Handler, Arg1>* this_handler)
740 {
741  asio_handler_invoke_helpers::invoke(
742  ASIO_MOVE_CAST(Function)(function), this_handler->handler_);
743 #if defined(ASIO_NO_DEPRECATED)
744  return asio_handler_invoke_is_no_longer_used();
745 #endif // defined(ASIO_NO_DEPRECATED)
746 }
747 
748 template <typename Handler, typename Arg1, typename Arg2>
749 class move_binder2
750 {
751 public:
752  move_binder2(int, ASIO_MOVE_ARG(Handler) handler,
753  const Arg1& arg1, ASIO_MOVE_ARG(Arg2) arg2)
754  : handler_(ASIO_MOVE_CAST(Handler)(handler)),
755  arg1_(arg1),
756  arg2_(ASIO_MOVE_CAST(Arg2)(arg2))
757  {
758  }
759 
760  move_binder2(move_binder2&& other)
761  : handler_(ASIO_MOVE_CAST(Handler)(other.handler_)),
762  arg1_(ASIO_MOVE_CAST(Arg1)(other.arg1_)),
763  arg2_(ASIO_MOVE_CAST(Arg2)(other.arg2_))
764  {
765  }
766 
767  void operator()()
768  {
769  handler_(static_cast<const Arg1&>(arg1_),
770  ASIO_MOVE_CAST(Arg2)(arg2_));
771  }
772 
773 //private:
774  Handler handler_;
775  Arg1 arg1_;
776  Arg2 arg2_;
777 };
778 
779 template <typename Handler, typename Arg1, typename Arg2>
780 inline asio_handler_allocate_is_deprecated
781 asio_handler_allocate(std::size_t size,
782  move_binder2<Handler, Arg1, Arg2>* this_handler)
783 {
784 #if defined(ASIO_NO_DEPRECATED)
785  asio_handler_alloc_helpers::allocate(size, this_handler->handler_);
786  return asio_handler_allocate_is_no_longer_used();
787 #else // defined(ASIO_NO_DEPRECATED)
788  return asio_handler_alloc_helpers::allocate(
789  size, this_handler->handler_);
790 #endif // defined(ASIO_NO_DEPRECATED)
791 }
792 
793 template <typename Handler, typename Arg1, typename Arg2>
794 inline asio_handler_deallocate_is_deprecated
795 asio_handler_deallocate(void* pointer, std::size_t size,
796  move_binder2<Handler, Arg1, Arg2>* this_handler)
797 {
798  asio_handler_alloc_helpers::deallocate(
799  pointer, size, this_handler->handler_);
800 #if defined(ASIO_NO_DEPRECATED)
801  return asio_handler_deallocate_is_no_longer_used();
802 #endif // defined(ASIO_NO_DEPRECATED)
803 }
804 
805 template <typename Handler, typename Arg1, typename Arg2>
806 inline bool asio_handler_is_continuation(
807  move_binder2<Handler, Arg1, Arg2>* this_handler)
808 {
809  return asio_handler_cont_helpers::is_continuation(
810  this_handler->handler_);
811 }
812 
813 template <typename Function, typename Handler, typename Arg1, typename Arg2>
814 inline asio_handler_invoke_is_deprecated
815 asio_handler_invoke(ASIO_MOVE_ARG(Function) function,
816  move_binder2<Handler, Arg1, Arg2>* this_handler)
817 {
818  asio_handler_invoke_helpers::invoke(
819  ASIO_MOVE_CAST(Function)(function), this_handler->handler_);
820 #if defined(ASIO_NO_DEPRECATED)
821  return asio_handler_invoke_is_no_longer_used();
822 #endif // defined(ASIO_NO_DEPRECATED)
823 }
824 
825 #endif // defined(ASIO_HAS_MOVE)
826 
827 } // namespace detail
828 
829 template <typename Handler, typename Arg1, typename Allocator>
830 struct associated_allocator<detail::binder1<Handler, Arg1>, Allocator>
831 {
833 
834  static type get(const detail::binder1<Handler, Arg1>& h,
835  const Allocator& a = Allocator()) ASIO_NOEXCEPT
836  {
837  return associated_allocator<Handler, Allocator>::get(h.handler_, a);
838  }
839 };
840 
841 template <typename Handler, typename Arg1, typename Arg2, typename Allocator>
842 struct associated_allocator<detail::binder2<Handler, Arg1, Arg2>, Allocator>
843 {
845 
846  static type get(const detail::binder2<Handler, Arg1, Arg2>& h,
847  const Allocator& a = Allocator()) ASIO_NOEXCEPT
848  {
849  return associated_allocator<Handler, Allocator>::get(h.handler_, a);
850  }
851 };
852 
853 template <typename Handler, typename Arg1, typename Executor>
854 struct associated_executor<detail::binder1<Handler, Arg1>, Executor>
856 {
857  typedef typename associated_executor<Handler, Executor>::type type;
858 
859  static type get(const detail::binder1<Handler, Arg1>& h,
860  const Executor& ex = Executor()) ASIO_NOEXCEPT
861  {
862  return associated_executor<Handler, Executor>::get(h.handler_, ex);
863  }
864 };
865 
866 template <typename Handler, typename Arg1, typename Arg2, typename Executor>
867 struct associated_executor<detail::binder2<Handler, Arg1, Arg2>, Executor>
869 {
870  typedef typename associated_executor<Handler, Executor>::type type;
871 
872  static type get(const detail::binder2<Handler, Arg1, Arg2>& h,
873  const Executor& ex = Executor()) ASIO_NOEXCEPT
874  {
875  return associated_executor<Handler, Executor>::get(h.handler_, ex);
876  }
877 };
878 
879 #if defined(ASIO_HAS_MOVE)
880 
881 template <typename Handler, typename Arg1, typename Allocator>
882 struct associated_allocator<detail::move_binder1<Handler, Arg1>, Allocator>
883 {
885 
886  static type get(const detail::move_binder1<Handler, Arg1>& h,
887  const Allocator& a = Allocator()) ASIO_NOEXCEPT
888  {
889  return associated_allocator<Handler, Allocator>::get(h.handler_, a);
890  }
891 };
892 
893 template <typename Handler, typename Arg1, typename Arg2, typename Allocator>
894 struct associated_allocator<
895  detail::move_binder2<Handler, Arg1, Arg2>, Allocator>
896 {
898 
899  static type get(const detail::move_binder2<Handler, Arg1, Arg2>& h,
900  const Allocator& a = Allocator()) ASIO_NOEXCEPT
901  {
902  return associated_allocator<Handler, Allocator>::get(h.handler_, a);
903  }
904 };
905 
906 template <typename Handler, typename Arg1, typename Executor>
907 struct associated_executor<detail::move_binder1<Handler, Arg1>, Executor>
909 {
910  typedef typename associated_executor<Handler, Executor>::type type;
911 
912  static type get(const detail::move_binder1<Handler, Arg1>& h,
913  const Executor& ex = Executor()) ASIO_NOEXCEPT
914  {
915  return associated_executor<Handler, Executor>::get(h.handler_, ex);
916  }
917 };
918 
919 template <typename Handler, typename Arg1, typename Arg2, typename Executor>
920 struct associated_executor<detail::move_binder2<Handler, Arg1, Arg2>, Executor>
922 {
923  typedef typename associated_executor<Handler, Executor>::type type;
924 
925  static type get(const detail::move_binder2<Handler, Arg1, Arg2>& h,
926  const Executor& ex = Executor()) ASIO_NOEXCEPT
927  {
928  return associated_executor<Handler, Executor>::get(h.handler_, ex);
929  }
930 };
931 
932 #endif // defined(ASIO_HAS_MOVE)
933 
934 } // namespace asio
935 
936 #include "asio/detail/pop_options.hpp"
937 
938 #endif // ASIO_DETAIL_BIND_HANDLER_HPP
asio_handler_invoke_is_deprecated asio_handler_invoke(Function &function,...)
Default handler invocation hook used for non-const function objects.
Definition: handler_invoke_hook.hpp:85
Definition: bind_handler.hpp:531
Definition: bind_handler.hpp:32
Definition: bind_handler.hpp:392
static type get(const T &t, const Allocator &a=Allocator()) ASIO_NOEXCEPT
If T has a nested type allocator_type, returns t.get_allocator().
Definition: associated_allocator.hpp:84
Definition: chrono.h:284
Definition: bind_handler.hpp:263
Traits type used to obtain the allocator associated with an object.
Definition: associated_allocator.hpp:72
Traits type used to obtain the executor associated with an object.
Definition: associated_executor.hpp:76
Definition: associated_executor.hpp:144
detail::associated_allocator_impl< T, Allocator >::type type
If T has a nested type allocator_type, T::allocator_type.
Definition: associated_allocator.hpp:79
Definition: any_io_executor.hpp:28
Definition: bind_handler.hpp:144