LegacyCompletionHandler.qbk 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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:LegacyCompletionHandler Legacy completion handler requirements]
  8. A legacy completion handler must meet the requirements for a [link
  9. boost_asio.reference.Handler handler]. A legacy completion handler must meet the
  10. requirements of `CopyConstructible` types (C++Std [copyconstructible]). A value
  11. `h` of a completion handler class should work correctly in the expression
  12. `h()`.
  13. [heading Examples]
  14. A free function as a completion handler:
  15. void completion_handler()
  16. {
  17. ...
  18. }
  19. A completion handler function object:
  20. struct completion_handler
  21. {
  22. ...
  23. void operator()()
  24. {
  25. ...
  26. }
  27. ...
  28. };
  29. A lambda as a completion handler:
  30. my_io_service.post(
  31. []()
  32. {
  33. ...
  34. });
  35. A non-static class member function adapted to a completion handler using
  36. `std::bind()`:
  37. void my_class::completion_handler()
  38. {
  39. ...
  40. }
  41. ...
  42. my_io_service.post(std::bind(&my_class::completion_handler, this));
  43. A non-static class member function adapted to a completion handler using
  44. `boost::bind()`:
  45. void my_class::completion_handler()
  46. {
  47. ...
  48. }
  49. ...
  50. my_io_service.post(boost::bind(&my_class::completion_handler, this));
  51. [endsect]