#include #include "asio/detail/push_options.hpp" namespace asio { template > class rf_task_t { public: typedef Allocator allocator_type; constexpr rf_task_t() {} explicit rf_task_t(const Allocator& allocator) : allocator_(allocator) {} template rf_task_t operator[](const OtherAllocator& allocator) const { return rf_task_t(allocator); } allocator_type get_allocator() const { return allocator_; } private: Allocator allocator_; }; constexpr rf_task_t<> rf_task; namespace detail { template class promise_handler { public: using result_type_t = T; using state_type = librf::state_t; template promise_handler(const rf_task_t &) : state_(state_type::typename _Alloc_state(true)) { } void operator()(T t) const { state_->set_value(std::move(t)); } void operator()(const asio::error_code& ec, T t) const { if (!ec) { state_->set_value(std::move(t)); } else { state_->set_exception(std::make_exception_ptr(asio::system_error(ec))); } } librf::counted_ptr state_; }; template<> class promise_handler { public: using result_type_t = void; using state_type = librf::state_t; template promise_handler(const rf_task_t &) : state_(state_type::typename _Alloc_state(true)) { } void operator()() const { state_->set_value(); } void operator()(const asio::error_code& ec) const { if (!ec) { state_->set_value(); } else { state_->set_exception(std::make_exception_ptr(asio::system_error(ec))); } } librf::counted_ptr state_; }; } // namespace detail template class async_result > { public: typedef librf::future_t type; explicit async_result(detail::promise_handler & h) : task_(std::move(h.state_)) { } librf::future_t get() { return std::move(task_); } private: librf::future_t task_; }; // Handler type specialisation for zero arg. template struct handler_type, ReturnType()> { typedef detail::promise_handler type; }; // Handler type specialisation for one arg. template struct handler_type, ReturnType(Arg1)> { typedef detail::promise_handler type; }; // Handler type specialisation for two arg. template struct handler_type, ReturnType(asio::error_code, Arg2)> { typedef detail::promise_handler type; }; template struct handler_type, ReturnType(asio::error_code)> { typedef detail::promise_handler type; }; } // namespace asio #include "asio/detail/pop_options.hpp"