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