]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/asio/include/boost/asio/use_future.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / asio / include / boost / asio / use_future.hpp
1 //
2 // use_future.hpp
3 // ~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2016 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_USE_FUTURE_HPP
12 #define BOOST_ASIO_USE_FUTURE_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 <memory>
20
21 #include <boost/asio/detail/push_options.hpp>
22
23 namespace boost {
24 namespace asio {
25
26 /// Class used to specify that an asynchronous operation should return a future.
27 /**
28 * The use_future_t class is used to indicate that an asynchronous operation
29 * should return a std::future object. A use_future_t object may be passed as a
30 * handler to an asynchronous operation, typically using the special value @c
31 * boost::asio::use_future. For example:
32 *
33 * @code std::future<std::size_t> my_future
34 * = my_socket.async_read_some(my_buffer, boost::asio::use_future); @endcode
35 *
36 * The initiating function (async_read_some in the above example) returns a
37 * future that will receive the result of the operation. If the operation
38 * completes with an error_code indicating failure, it is converted into a
39 * system_error and passed back to the caller via the future.
40 */
41 template <typename Allocator = std::allocator<void> >
42 class use_future_t
43 {
44 public:
45 /// The allocator type. The allocator is used when constructing the
46 /// @c std::promise object for a given asynchronous operation.
47 typedef Allocator allocator_type;
48
49 /// Construct using default-constructed allocator.
50 BOOST_ASIO_CONSTEXPR use_future_t()
51 {
52 }
53
54 /// Construct using specified allocator.
55 explicit use_future_t(const Allocator& allocator)
56 : allocator_(allocator)
57 {
58 }
59
60 /// Specify an alternate allocator.
61 template <typename OtherAllocator>
62 use_future_t<OtherAllocator> operator[](const OtherAllocator& allocator) const
63 {
64 return use_future_t<OtherAllocator>(allocator);
65 }
66
67 /// Obtain allocator.
68 allocator_type get_allocator() const
69 {
70 return allocator_;
71 }
72
73 private:
74 Allocator allocator_;
75 };
76
77 /// A special value, similar to std::nothrow.
78 /**
79 * See the documentation for boost::asio::use_future_t for a usage example.
80 */
81 #if defined(BOOST_ASIO_HAS_CONSTEXPR) || defined(GENERATING_DOCUMENTATION)
82 constexpr use_future_t<> use_future;
83 #elif defined(BOOST_ASIO_MSVC)
84 __declspec(selectany) use_future_t<> use_future;
85 #endif
86
87 } // namespace asio
88 } // namespace boost
89
90 #include <boost/asio/detail/pop_options.hpp>
91
92 #include <boost/asio/impl/use_future.hpp>
93
94 #endif // BOOST_ASIO_USE_FUTURE_HPP