diff options
Diffstat (limited to '3rdparty/asio/include/asio/impl/use_future.hpp')
-rw-r--r-- | 3rdparty/asio/include/asio/impl/use_future.hpp | 206 |
1 files changed, 161 insertions, 45 deletions
diff --git a/3rdparty/asio/include/asio/impl/use_future.hpp b/3rdparty/asio/include/asio/impl/use_future.hpp index e06c4001742..4a35ab4754d 100644 --- a/3rdparty/asio/include/asio/impl/use_future.hpp +++ b/3rdparty/asio/include/asio/impl/use_future.hpp @@ -2,7 +2,7 @@ // impl/use_future.hpp // ~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2021 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,11 +16,12 @@ #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include "asio/detail/config.hpp" -#include <future> #include <tuple> #include "asio/async_result.hpp" #include "asio/detail/memory.hpp" +#include "asio/dispatch.hpp" #include "asio/error_code.hpp" +#include "asio/execution.hpp" #include "asio/packaged_task.hpp" #include "asio/system_error.hpp" #include "asio/system_executor.hpp" @@ -174,7 +175,7 @@ class promise_invoker public: promise_invoker(const shared_ptr<std::promise<T> >& p, ASIO_MOVE_ARG(F) f) - : p_(p), f_(f) + : p_(p), f_(ASIO_MOVE_CAST(F)(f)) { } @@ -201,7 +202,7 @@ private: // An executor that adapts the system_executor to capture any exeption thrown // by a submitted function object and save it into a promise. -template <typename T> +template <typename T, typename Blocking = execution::blocking_t::possibly_t> class promise_executor { public: @@ -210,6 +211,32 @@ public: { } + static ASIO_CONSTEXPR Blocking query(execution::blocking_t) + { + return Blocking(); + } + + promise_executor<T, execution::blocking_t::possibly_t> + require(execution::blocking_t::possibly_t) const + { + return promise_executor<T, execution::blocking_t::possibly_t>(p_); + } + + promise_executor<T, execution::blocking_t::never_t> + require(execution::blocking_t::never_t) const + { + return promise_executor<T, execution::blocking_t::never_t>(p_); + } + + template <typename F> + void execute(ASIO_MOVE_ARG(F) f) const + { + execution::execute( + asio::require(system_executor(), Blocking()), + promise_invoker<T, F>(p_, ASIO_MOVE_CAST(F)(f))); + } + +#if !defined(ASIO_NO_TS_EXECUTORS) execution_context& context() const ASIO_NOEXCEPT { return system_executor().context(); @@ -237,6 +264,7 @@ public: system_executor().defer( promise_invoker<T, F>(p_, ASIO_MOVE_CAST(F)(f)), a); } +#endif // !defined(ASIO_NO_TS_EXECUTORS) friend bool operator==(const promise_executor& a, const promise_executor& b) ASIO_NOEXCEPT @@ -277,10 +305,8 @@ protected: template <typename Allocator> void create_promise(const Allocator& a) { - p_ = std::allocate_shared<std::promise<T>>( - typename Allocator::template rebind<char>::other(a), - std::allocator_arg, - typename Allocator::template rebind<char>::other(a)); + ASIO_REBIND_ALLOC(Allocator, char) b(a); + p_ = std::allocate_shared<std::promise<T>>(b, std::allocator_arg, b); } shared_ptr<std::promise<T> > p_; @@ -545,6 +571,8 @@ template <typename Arg> class promise_handler_selector<void(std::exception_ptr, Arg)> : public promise_handler_ex_1<Arg> {}; +#if defined(ASIO_HAS_VARIADIC_TEMPLATES) + template <typename... Arg> class promise_handler_selector<void(Arg...)> : public promise_handler_n<std::tuple<Arg...> > {}; @@ -557,6 +585,32 @@ template <typename... Arg> class promise_handler_selector<void(std::exception_ptr, Arg...)> : public promise_handler_ex_n<std::tuple<Arg...> > {}; +#else // defined(ASIO_HAS_VARIADIC_TEMPLATES) + +#define ASIO_PRIVATE_PROMISE_SELECTOR_DEF(n) \ + template <typename Arg, ASIO_VARIADIC_TPARAMS(n)> \ + class promise_handler_selector< \ + void(Arg, ASIO_VARIADIC_TARGS(n))> \ + : public promise_handler_n< \ + std::tuple<Arg, ASIO_VARIADIC_TARGS(n)> > {}; \ + \ + template <typename Arg, ASIO_VARIADIC_TPARAMS(n)> \ + class promise_handler_selector< \ + void(asio::error_code, Arg, ASIO_VARIADIC_TARGS(n))> \ + : public promise_handler_ec_n< \ + std::tuple<Arg, ASIO_VARIADIC_TARGS(n)> > {}; \ + \ + template <typename Arg, ASIO_VARIADIC_TPARAMS(n)> \ + class promise_handler_selector< \ + void(std::exception_ptr, Arg, ASIO_VARIADIC_TARGS(n))> \ + : public promise_handler_ex_n< \ + std::tuple<Arg, ASIO_VARIADIC_TARGS(n)> > {}; \ + /**/ + ASIO_VARIADIC_GENERATE_5(ASIO_PRIVATE_PROMISE_SELECTOR_DEF) +#undef ASIO_PRIVATE_PROMISE_SELECTOR_DEF + +#endif // defined(ASIO_HAS_VARIADIC_TEMPLATES) + // Completion handlers produced from the use_future completion token, when not // using use_future::operator(). template <typename Signature, typename Allocator> @@ -582,13 +636,36 @@ private: Allocator allocator_; }; +template <typename Function> +struct promise_function_wrapper +{ + explicit promise_function_wrapper(Function& f) + : function_(ASIO_MOVE_CAST(Function)(f)) + { + } + + explicit promise_function_wrapper(const Function& f) + : function_(f) + { + } + + void operator()() + { + function_(); + } + + Function function_; +}; + +#if !defined(ASIO_NO_DEPRECATED) + template <typename Function, typename Signature, typename Allocator> inline void asio_handler_invoke(Function& f, promise_handler<Signature, Allocator>* h) { typename promise_handler<Signature, Allocator>::executor_type ex(h->get_executor()); - ex.dispatch(ASIO_MOVE_CAST(Function)(f), std::allocator<void>()); + asio::dispatch(ex, promise_function_wrapper<Function>(f)); } template <typename Function, typename Signature, typename Allocator> @@ -597,9 +674,11 @@ inline void asio_handler_invoke(const Function& f, { typename promise_handler<Signature, Allocator>::executor_type ex(h->get_executor()); - ex.dispatch(f, std::allocator<void>()); + asio::dispatch(ex, promise_function_wrapper<Function>(f)); } +#endif // !defined(ASIO_NO_DEPRECATED) + // Helper base class for async_result specialisation. template <typename Signature, typename Allocator> class promise_async_result @@ -694,6 +773,8 @@ private: Allocator allocator_; }; +#if !defined(ASIO_NO_DEPRECATED) + template <typename Function, typename Function1, typename Allocator, typename Result> inline void asio_handler_invoke(Function& f, @@ -701,7 +782,7 @@ inline void asio_handler_invoke(Function& f, { typename packaged_handler<Function1, Allocator, Result>::executor_type ex(h->get_executor()); - ex.dispatch(ASIO_MOVE_CAST(Function)(f), std::allocator<void>()); + asio::dispatch(ex, promise_function_wrapper<Function>(f)); } template <typename Function, @@ -711,9 +792,11 @@ inline void asio_handler_invoke(const Function& f, { typename packaged_handler<Function1, Allocator, Result>::executor_type ex(h->get_executor()); - ex.dispatch(f, std::allocator<void>()); + asio::dispatch(ex, promise_function_wrapper<Function>(f)); } +#endif // !defined(ASIO_NO_DEPRECATED) + // Helper base class for async_result specialisation. template <typename Function, typename Allocator, typename Result> class packaged_async_result @@ -853,55 +936,88 @@ public: #endif // defined(ASIO_HAS_VARIADIC_TEMPLATES) -#if !defined(ASIO_NO_DEPRECATED) +namespace traits { + +#if !defined(ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT) -template <typename Allocator, typename Signature> -struct handler_type<use_future_t<Allocator>, Signature> +template <typename T, typename Blocking> +struct equality_comparable< + asio::detail::promise_executor<T, Blocking> > { - typedef typename async_result<use_future_t<Allocator>, - Signature>::completion_handler_type type; + ASIO_STATIC_CONSTEXPR(bool, is_valid = true); + ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true); }; -template <typename Signature, typename Allocator> -class async_result<detail::promise_handler<Signature, Allocator> > - : public detail::promise_async_result<Signature, Allocator> +#endif // !defined(ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT) + +#if !defined(ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT) + +template <typename T, typename Blocking, typename Function> +struct execute_member< + asio::detail::promise_executor<T, Blocking>, Function> { -public: - typedef typename detail::promise_async_result< - Signature, Allocator>::return_type type; + ASIO_STATIC_CONSTEXPR(bool, is_valid = true); + ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false); + typedef void result_type; +}; - explicit async_result( - typename detail::promise_async_result< - Signature, Allocator>::completion_handler_type& h) - : detail::promise_async_result<Signature, Allocator>(h) +#endif // !defined(ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT) + +#if !defined(ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_TRAIT) + +template <typename T, typename Blocking, typename Property> +struct query_static_constexpr_member< + asio::detail::promise_executor<T, Blocking>, + Property, + typename asio::enable_if< + asio::is_convertible< + Property, + asio::execution::blocking_t + >::value + >::type + > +{ + ASIO_STATIC_CONSTEXPR(bool, is_valid = true); + ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true); + typedef Blocking result_type; + + static ASIO_CONSTEXPR result_type value() ASIO_NOEXCEPT { + return Blocking(); } }; -template <typename Function, typename Allocator, typename Signature> -struct handler_type<detail::packaged_token<Function, Allocator>, Signature> +#endif // !defined(ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_TRAIT) + +#if !defined(ASIO_HAS_DEDUCED_REQUIRE_MEMBER_TRAIT) + +template <typename T, typename Blocking> +struct require_member< + asio::detail::promise_executor<T, Blocking>, + execution::blocking_t::possibly_t + > { - typedef typename async_result<detail::packaged_token<Function, Allocator>, - Signature>::completion_handler_type type; + ASIO_STATIC_CONSTEXPR(bool, is_valid = true); + ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true); + typedef asio::detail::promise_executor<T, + execution::blocking_t::possibly_t> result_type; }; -template <typename Function, typename Allocator, typename Result> -class async_result<detail::packaged_handler<Function, Allocator, Result> > - : public detail::packaged_async_result<Function, Allocator, Result> +template <typename T, typename Blocking> +struct require_member< + asio::detail::promise_executor<T, Blocking>, + execution::blocking_t::never_t + > { -public: - typedef typename detail::packaged_async_result< - Function, Allocator, Result>::return_type type; - - explicit async_result( - typename detail::packaged_async_result< - Function, Allocator, Result>::completion_handler_type& h) - : detail::packaged_async_result<Function, Allocator, Result>(h) - { - } + ASIO_STATIC_CONSTEXPR(bool, is_valid = true); + ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true); + typedef asio::detail::promise_executor<T, + execution::blocking_t::never_t> result_type; }; -#endif // !defined(ASIO_NO_DEPRECATED) +#endif // !defined(ASIO_HAS_DEDUCED_REQUIRE_MEMBER_TRAIT) + +} // namespace traits #endif // !defined(GENERATING_DOCUMENTATION) |