5 // Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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)
11 #ifndef BOOST_ASIO_USE_FUTURE_HPP
12 #define BOOST_ASIO_USE_FUTURE_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/config.hpp>
21 #include <boost/asio/detail/push_options.hpp>
26 /// Class used to specify that an asynchronous operation should return a future.
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:
33 * @code std::future<std::size_t> my_future
34 * = my_socket.async_read_some(my_buffer, boost::asio::use_future); @endcode
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.
41 template <typename Allocator = std::allocator<void> >
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;
49 /// Construct using default-constructed allocator.
50 BOOST_ASIO_CONSTEXPR use_future_t()
54 /// Construct using specified allocator.
55 explicit use_future_t(const Allocator& allocator)
56 : allocator_(allocator)
60 /// Specify an alternate allocator.
61 template <typename OtherAllocator>
62 use_future_t<OtherAllocator> operator[](const OtherAllocator& allocator) const
64 return use_future_t<OtherAllocator>(allocator);
68 allocator_type get_allocator() const
77 /// A special value, similar to std::nothrow.
79 * See the documentation for boost::asio::use_future_t for a usage example.
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;
90 #include <boost/asio/detail/pop_options.hpp>
92 #include <boost/asio/impl/use_future.hpp>
94 #endif // BOOST_ASIO_USE_FUTURE_HPP