Chris@16: // Chris@16: // use_future.hpp Chris@16: // ~~~~~~~~~~~~~~ Chris@16: // Chris@101: // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com) Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: Chris@16: #ifndef BOOST_ASIO_USE_FUTURE_HPP Chris@16: #define BOOST_ASIO_USE_FUTURE_HPP Chris@16: Chris@16: #if defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: # pragma once Chris@16: #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace asio { Chris@16: Chris@16: /// Class used to specify that an asynchronous operation should return a future. Chris@16: /** Chris@16: * The use_future_t class is used to indicate that an asynchronous operation Chris@16: * should return a std::future object. A use_future_t object may be passed as a Chris@16: * handler to an asynchronous operation, typically using the special value @c Chris@16: * boost::asio::use_future. For example: Chris@16: * Chris@16: * @code std::future my_future Chris@16: * = my_socket.async_read_some(my_buffer, boost::asio::use_future); @endcode Chris@16: * Chris@16: * The initiating function (async_read_some in the above example) returns a Chris@16: * future that will receive the result of the operation. If the operation Chris@16: * completes with an error_code indicating failure, it is converted into a Chris@16: * system_error and passed back to the caller via the future. Chris@16: */ Chris@16: template > Chris@16: class use_future_t Chris@16: { Chris@16: public: Chris@16: /// The allocator type. The allocator is used when constructing the Chris@16: /// @c std::promise object for a given asynchronous operation. Chris@16: typedef Allocator allocator_type; Chris@16: Chris@16: /// Construct using default-constructed allocator. Chris@16: BOOST_ASIO_CONSTEXPR use_future_t() Chris@16: { Chris@16: } Chris@16: Chris@16: /// Construct using specified allocator. Chris@16: explicit use_future_t(const Allocator& allocator) Chris@16: : allocator_(allocator) Chris@16: { Chris@16: } Chris@16: Chris@16: /// Specify an alternate allocator. Chris@16: template Chris@16: use_future_t operator[](const OtherAllocator& allocator) const Chris@16: { Chris@16: return use_future_t(allocator); Chris@16: } Chris@16: Chris@16: /// Obtain allocator. Chris@16: allocator_type get_allocator() const Chris@16: { Chris@16: return allocator_; Chris@16: } Chris@16: Chris@16: private: Chris@16: Allocator allocator_; Chris@16: }; Chris@16: Chris@16: /// A special value, similar to std::nothrow. Chris@16: /** Chris@16: * See the documentation for boost::asio::use_future_t for a usage example. Chris@16: */ Chris@16: #if defined(BOOST_ASIO_HAS_CONSTEXPR) || defined(GENERATING_DOCUMENTATION) Chris@16: constexpr use_future_t<> use_future; Chris@16: #elif defined(BOOST_ASIO_MSVC) Chris@16: __declspec(selectany) use_future_t<> use_future; Chris@16: #endif Chris@16: Chris@16: } // namespace asio Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: #endif // BOOST_ASIO_USE_FUTURE_HPP