packaged_task.hpp 1.7 KB

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