bind_handler.hpp 23 KB

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