bind_handler.hpp 29 KB

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