// // experimental/use_promise.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2021-2023 Klemens D. Morgenstern // (klemens dot morgenstern at gmx dot net) // // 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) // #ifndef BOOST_ASIO_EXPERIMENTAL_USE_PROMISE_HPP #define BOOST_ASIO_EXPERIMENTAL_USE_PROMISE_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include #include #include #include namespace boost { namespace asio { namespace experimental { template > struct use_promise_t { /// The allocator type. The allocator is used when constructing the /// @c promise object for a given asynchronous operation. typedef Allocator allocator_type; /// Construct using default-constructed allocator. BOOST_ASIO_CONSTEXPR use_promise_t() { } /// Construct using specified allocator. explicit use_promise_t(const Allocator& allocator) : allocator_(allocator) { } /// Obtain allocator. allocator_type get_allocator() const BOOST_ASIO_NOEXCEPT { return allocator_; } /// Adapts an executor to add the @c use_promise_t completion token as the /// default. template struct executor_with_default : InnerExecutor { /// Specify @c use_promise_t as the default completion token type. typedef use_promise_t default_completion_token_type; /// Construct the adapted executor from the inner executor type. executor_with_default(const InnerExecutor& ex) BOOST_ASIO_NOEXCEPT : InnerExecutor(ex) { } /// Convert the specified executor to the inner executor type, then use /// that to construct the adapted executor. template executor_with_default(const OtherExecutor& ex, typename constraint< is_convertible::value >::type = 0) BOOST_ASIO_NOEXCEPT : InnerExecutor(ex) { } }; /// Function helper to adapt an I/O object to use @c use_promise_t as its /// default completion token type. template static typename decay::type::template rebind_executor< executor_with_default::type::executor_type> >::other as_default_on(BOOST_ASIO_MOVE_ARG(T) object) { return typename decay::type::template rebind_executor< executor_with_default::type::executor_type> >::other(BOOST_ASIO_MOVE_CAST(T)(object)); } /// Specify an alternate allocator. template use_promise_t rebind(const OtherAllocator& allocator) const { return use_promise_t(allocator); } private: Allocator allocator_; }; constexpr use_promise_t<> use_promise; } // namespace experimental } // namespace asio } // namespace boost #include #include #endif // BOOST_ASIO_EXPERIMENTAL_USE_CORO_HPP