packaged_task.hpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //
  2. // packaged_task.hpp
  3. // ~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2024 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_PACKAGED_TASK_HPP
  11. #define BOOST_ASIO_PACKAGED_TASK_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/detail/future.hpp>
  17. #if defined(BOOST_ASIO_HAS_STD_FUTURE_CLASS) \
  18. || defined(GENERATING_DOCUMENTATION)
  19. #include <boost/asio/async_result.hpp>
  20. #include <boost/asio/detail/type_traits.hpp>
  21. #include <boost/asio/detail/push_options.hpp>
  22. namespace boost {
  23. namespace asio {
  24. /// Partial specialisation of @c async_result for @c std::packaged_task.
  25. template <typename Result, typename... Args, typename Signature>
  26. class async_result<std::packaged_task<Result(Args...)>, Signature>
  27. {
  28. public:
  29. /// The packaged task is the concrete completion handler type.
  30. typedef std::packaged_task<Result(Args...)> completion_handler_type;
  31. /// The return type of the initiating function is the future obtained from
  32. /// the packaged task.
  33. typedef std::future<Result> return_type;
  34. /// The constructor extracts the future from the packaged task.
  35. explicit async_result(completion_handler_type& h)
  36. : future_(h.get_future())
  37. {
  38. }
  39. /// Returns the packaged task's future.
  40. return_type get()
  41. {
  42. return std::move(future_);
  43. }
  44. private:
  45. return_type future_;
  46. };
  47. } // namespace asio
  48. } // namespace boost
  49. #include <boost/asio/detail/pop_options.hpp>
  50. #endif // defined(BOOST_ASIO_HAS_STD_FUTURE_CLASS)
  51. // || defined(GENERATING_DOCUMENTATION)
  52. #endif // BOOST_ASIO_PACKAGED_TASK_HPP