IteratorConnectHandler.qbk 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. [/
  2. / Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  3. /
  4. / Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. /]
  7. [section:IteratorConnectHandler Iterator connect handler requirements]
  8. An iterator connect handler must meet the requirements for a [link
  9. boost_asio.reference.Handler handler]. A value `h` of an iterator connect handler
  10. class should work correctly in the expression `h(ec, i)`, where `ec` is an
  11. lvalue of type `const error_code` and `i` is an lvalue of the type `Iterator`
  12. used in the corresponding `connect()` or async_connect()` function.
  13. [heading Examples]
  14. A free function as an iterator connect handler:
  15. void connect_handler(
  16. const boost::system::error_code& ec,
  17. boost::asio::ip::tcp::resolver::iterator iterator)
  18. {
  19. ...
  20. }
  21. An iterator connect handler function object:
  22. struct connect_handler
  23. {
  24. ...
  25. template <typename Iterator>
  26. void operator()(
  27. const boost::system::error_code& ec,
  28. Iterator iterator)
  29. {
  30. ...
  31. }
  32. ...
  33. };
  34. A lambda as an iterator connect handler:
  35. boost::asio::async_connect(...,
  36. [](const boost::system::error_code& ec,
  37. boost::asio::ip::tcp::resolver::iterator iterator)
  38. {
  39. ...
  40. });
  41. A non-static class member function adapted to an iterator connect handler using
  42. `std::bind()`:
  43. void my_class::connect_handler(
  44. const boost::system::error_code& ec,
  45. boost::asio::ip::tcp::resolver::iterator iterator)
  46. {
  47. ...
  48. }
  49. ...
  50. boost::asio::async_connect(...,
  51. std::bind(&my_class::connect_handler,
  52. this, std::placeholders::_1,
  53. std::placeholders::_2));
  54. A non-static class member function adapted to an iterator connect handler using
  55. `boost::bind()`:
  56. void my_class::connect_handler(
  57. const boost::system::error_code& ec,
  58. boost::asio::ip::tcp::resolver::iterator iterator)
  59. {
  60. ...
  61. }
  62. ...
  63. boost::asio::async_connect(...,
  64. boost::bind(&my_class::connect_handler,
  65. this, boost::asio::placeholders::error,
  66. boost::asio::placeholders::iterator));
  67. [endsect]