diff options
Diffstat (limited to '3rdparty/asio/include/asio/use_future.hpp')
-rw-r--r-- | 3rdparty/asio/include/asio/use_future.hpp | 52 |
1 files changed, 34 insertions, 18 deletions
diff --git a/3rdparty/asio/include/asio/use_future.hpp b/3rdparty/asio/include/asio/use_future.hpp index 2a0e24ff94d..26f5ae1fed0 100644 --- a/3rdparty/asio/include/asio/use_future.hpp +++ b/3rdparty/asio/include/asio/use_future.hpp @@ -2,7 +2,7 @@ // use_future.hpp // ~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -16,8 +16,9 @@ #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include "asio/detail/config.hpp" +#include "asio/detail/future.hpp" -#if defined(ASIO_HAS_STD_FUTURE) \ +#if defined(ASIO_HAS_STD_FUTURE_CLASS) \ || defined(GENERATING_DOCUMENTATION) #include <memory> @@ -36,12 +37,14 @@ class packaged_handler; } // namespace detail -/// Class used to specify that an asynchronous operation should return a future. +/// A @ref completion_token type that causes an asynchronous operation to return +/// a future. /** - * The use_future_t class is used to indicate that an asynchronous operation - * should return a std::future object. A use_future_t object may be passed as a - * handler to an asynchronous operation, typically using the special value @c - * asio::use_future. For example: + * The use_future_t class is a completion token type that is used to indicate + * that an asynchronous operation should return a std::future object. A + * use_future_t object may be passed as a completion token to an asynchronous + * operation, typically using the special value @c asio::use_future. For + * example: * * @code std::future<std::size_t> my_future * = my_socket.async_read_some(my_buffer, asio::use_future); @endcode @@ -51,7 +54,7 @@ class packaged_handler; * completes with an error_code indicating failure, it is converted into a * system_error and passed back to the caller via the future. */ -template <typename Allocator = std::allocator<void> > +template <typename Allocator = std::allocator<void>> class use_future_t { public: @@ -60,7 +63,7 @@ public: typedef Allocator allocator_type; /// Construct using default-constructed allocator. - ASIO_CONSTEXPR use_future_t() + constexpr use_future_t() { } @@ -113,23 +116,36 @@ public: #if defined(GENERATING_DOCUMENTATION) unspecified #else // defined(GENERATING_DOCUMENTATION) - detail::packaged_token<typename decay<Function>::type, Allocator> + detail::packaged_token<decay_t<Function>, Allocator> #endif // defined(GENERATING_DOCUMENTATION) - operator()(ASIO_MOVE_ARG(Function) f) const; + operator()(Function&& f) const; private: - Allocator allocator_; + // Helper type to ensure that use_future can be constexpr default-constructed + // even when std::allocator<void> can't be. + struct std_allocator_void + { + constexpr std_allocator_void() + { + } + + operator std::allocator<void>() const + { + return std::allocator<void>(); + } + }; + + conditional_t< + is_same<std::allocator<void>, Allocator>::value, + std_allocator_void, Allocator> allocator_; }; -/// A special value, similar to std::nothrow. +/// A @ref completion_token object that causes an asynchronous operation to +/// return a future. /** * See the documentation for asio::use_future_t for a usage example. */ -#if defined(ASIO_HAS_CONSTEXPR) || defined(GENERATING_DOCUMENTATION) constexpr use_future_t<> use_future; -#elif defined(ASIO_MSVC) -__declspec(selectany) use_future_t<> use_future; -#endif } // namespace asio @@ -137,7 +153,7 @@ __declspec(selectany) use_future_t<> use_future; #include "asio/impl/use_future.hpp" -#endif // defined(ASIO_HAS_STD_FUTURE) +#endif // defined(ASIO_HAS_STD_FUTURE_CLASS) // || defined(GENERATING_DOCUMENTATION) #endif // ASIO_USE_FUTURE_HPP |