]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/asio/packaged_task.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / asio / packaged_task.hpp
CommitLineData
b32b8144
FG
1//
2// packaged_task.hpp
3// ~~~~~~~~~~~~~~~~~
4//
92f5a8d4 5// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
b32b8144
FG
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>
92f5a8d4 19#include <boost/asio/detail/future.hpp>
b32b8144 20
92f5a8d4 21#if defined(BOOST_ASIO_HAS_STD_FUTURE_CLASS) \
b32b8144
FG
22 || defined(GENERATING_DOCUMENTATION)
23
b32b8144
FG
24#include <boost/asio/async_result.hpp>
25#include <boost/asio/detail/type_traits.hpp>
26#include <boost/asio/detail/variadic_templates.hpp>
27
28#include <boost/asio/detail/push_options.hpp>
29
30namespace boost {
31namespace asio {
32
33#if defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES) \
34 || defined(GENERATING_DOCUMENTATION)
35
36/// Partial specialisation of @c async_result for @c std::packaged_task.
37template <typename Result, typename... Args, typename Signature>
38class async_result<std::packaged_task<Result(Args...)>, Signature>
39{
40public:
41 /// The packaged task is the concrete completion handler type.
42 typedef std::packaged_task<Result(Args...)> completion_handler_type;
43
44 /// The return type of the initiating function is the future obtained from
45 /// the packaged task.
46 typedef std::future<Result> return_type;
47
48 /// The constructor extracts the future from the packaged task.
49 explicit async_result(completion_handler_type& h)
50 : future_(h.get_future())
51 {
52 }
53
54 /// Returns the packaged task's future.
55 return_type get()
56 {
57 return std::move(future_);
58 }
59
60private:
61 return_type future_;
62};
63
64#else // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
65 // || defined(GENERATING_DOCUMENTATION)
66
67template <typename Result, typename Signature>
68struct async_result<std::packaged_task<Result()>, Signature>
69{
70 typedef std::packaged_task<Result()> completion_handler_type;
71 typedef std::future<Result> return_type;
72
73 explicit async_result(completion_handler_type& h)
74 : future_(h.get_future())
75 {
76 }
77
78 return_type get()
79 {
80 return std::move(future_);
81 }
82
83private:
84 return_type future_;
85};
86
87#define BOOST_ASIO_PRIVATE_ASYNC_RESULT_DEF(n) \
88 template <typename Result, \
89 BOOST_ASIO_VARIADIC_TPARAMS(n), typename Signature> \
90 class async_result< \
91 std::packaged_task<Result(BOOST_ASIO_VARIADIC_TARGS(n))>, Signature> \
92 { \
93 public: \
94 typedef std::packaged_task< \
95 Result(BOOST_ASIO_VARIADIC_TARGS(n))> \
96 completion_handler_type; \
97 \
98 typedef std::future<Result> return_type; \
99 \
100 explicit async_result(completion_handler_type& h) \
101 : future_(h.get_future()) \
102 { \
103 } \
104 \
105 return_type get() \
106 { \
107 return std::move(future_); \
108 } \
109 \
110 private: \
111 return_type future_; \
112 }; \
113 /**/
114 BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_ASYNC_RESULT_DEF)
115#undef BOOST_ASIO_PRIVATE_ASYNC_RESULT_DEF
116
117#endif // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
118 // || defined(GENERATING_DOCUMENTATION)
119
120} // namespace asio
121} // namespace boost
122
123#include <boost/asio/detail/pop_options.hpp>
124
92f5a8d4 125#endif // defined(BOOST_ASIO_HAS_STD_FUTURE_CLASS)
b32b8144
FG
126 // || defined(GENERATING_DOCUMENTATION)
127
128#endif // BOOST_ASIO_PACKAGED_TASK_HPP