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 | |
11 | #ifndef BOOST_ASIO_PACKAGED_TASK_HPP |
12 | #define BOOST_ASIO_PACKAGED_TASK_HPP |
13 | |
14 | #if defined(_MSC_VER) && (_MSC_VER >= 1200) |
15 | # pragma once |
16 | #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) |
17 | |
18 | #include <boost/asio/detail/config.hpp> |
19 | #include <boost/asio/detail/future.hpp> |
20 | |
21 | #if defined(BOOST_ASIO_HAS_STD_FUTURE_CLASS) \ |
22 | || defined(GENERATING_DOCUMENTATION) |
23 | |
24 | #include <boost/asio/async_result.hpp> |
25 | #include <boost/asio/detail/type_traits.hpp> |
26 | |
27 | #include <boost/asio/detail/push_options.hpp> |
28 | |
29 | namespace boost { |
30 | namespace asio { |
31 | |
32 | /// Partial specialisation of @c async_result for @c std::packaged_task. |
33 | template <typename Result, typename... Args, typename Signature> |
34 | class async_result<std::packaged_task<Result(Args...)>, Signature> |
35 | { |
36 | public: |
37 | /// The packaged task is the concrete completion handler type. |
38 | typedef std::packaged_task<Result(Args...)> completion_handler_type; |
39 | |
40 | /// The return type of the initiating function is the future obtained from |
41 | /// the packaged task. |
42 | typedef std::future<Result> return_type; |
43 | |
44 | /// The constructor extracts the future from the packaged task. |
45 | explicit async_result(completion_handler_type& h) |
46 | : future_(h.get_future()) |
47 | { |
48 | } |
49 | |
50 | /// Returns the packaged task's future. |
51 | return_type get() |
52 | { |
53 | return std::move(future_); |
54 | } |
55 | |
56 | private: |
57 | return_type future_; |
58 | }; |
59 | |
60 | } // namespace asio |
61 | } // namespace boost |
62 | |
63 | #include <boost/asio/detail/pop_options.hpp> |
64 | |
65 | #endif // defined(BOOST_ASIO_HAS_STD_FUTURE_CLASS) |
66 | // || defined(GENERATING_DOCUMENTATION) |
67 | |
68 | #endif // BOOST_ASIO_PACKAGED_TASK_HPP |
69 | |