123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618 |
- #ifndef BOOST_ASIO_BIND_IMMEDIATE_EXECUTOR_HPP
- #define BOOST_ASIO_BIND_IMMEDIATE_EXECUTOR_HPP
- #if defined(_MSC_VER) && (_MSC_VER >= 1200)
- # pragma once
- #endif
- #include <boost/asio/detail/config.hpp>
- #include <boost/asio/associated_executor.hpp>
- #include <boost/asio/associated_immediate_executor.hpp>
- #include <boost/asio/associator.hpp>
- #include <boost/asio/async_result.hpp>
- #include <boost/asio/detail/initiation_base.hpp>
- #include <boost/asio/detail/type_traits.hpp>
- #include <boost/asio/detail/push_options.hpp>
- namespace boost {
- namespace asio {
- namespace detail {
- template <typename T, typename = void>
- struct immediate_executor_binder_result_type
- {
- protected:
- typedef void result_type_or_void;
- };
- template <typename T>
- struct immediate_executor_binder_result_type<T, void_t<typename T::result_type>>
- {
- typedef typename T::result_type result_type;
- protected:
- typedef result_type result_type_or_void;
- };
- template <typename R>
- struct immediate_executor_binder_result_type<R(*)()>
- {
- typedef R result_type;
- protected:
- typedef result_type result_type_or_void;
- };
- template <typename R>
- struct immediate_executor_binder_result_type<R(&)()>
- {
- typedef R result_type;
- protected:
- typedef result_type result_type_or_void;
- };
- template <typename R, typename A1>
- struct immediate_executor_binder_result_type<R(*)(A1)>
- {
- typedef R result_type;
- protected:
- typedef result_type result_type_or_void;
- };
- template <typename R, typename A1>
- struct immediate_executor_binder_result_type<R(&)(A1)>
- {
- typedef R result_type;
- protected:
- typedef result_type result_type_or_void;
- };
- template <typename R, typename A1, typename A2>
- struct immediate_executor_binder_result_type<R(*)(A1, A2)>
- {
- typedef R result_type;
- protected:
- typedef result_type result_type_or_void;
- };
- template <typename R, typename A1, typename A2>
- struct immediate_executor_binder_result_type<R(&)(A1, A2)>
- {
- typedef R result_type;
- protected:
- typedef result_type result_type_or_void;
- };
- template <typename T, typename = void>
- struct immediate_executor_binder_argument_type {};
- template <typename T>
- struct immediate_executor_binder_argument_type<T,
- void_t<typename T::argument_type>>
- {
- typedef typename T::argument_type argument_type;
- };
- template <typename R, typename A1>
- struct immediate_executor_binder_argument_type<R(*)(A1)>
- {
- typedef A1 argument_type;
- };
- template <typename R, typename A1>
- struct immediate_executor_binder_argument_type<R(&)(A1)>
- {
- typedef A1 argument_type;
- };
- template <typename T, typename = void>
- struct immediate_executor_binder_argument_types {};
- template <typename T>
- struct immediate_executor_binder_argument_types<T,
- void_t<typename T::first_argument_type>>
- {
- typedef typename T::first_argument_type first_argument_type;
- typedef typename T::second_argument_type second_argument_type;
- };
- template <typename R, typename A1, typename A2>
- struct immediate_executor_binder_argument_type<R(*)(A1, A2)>
- {
- typedef A1 first_argument_type;
- typedef A2 second_argument_type;
- };
- template <typename R, typename A1, typename A2>
- struct immediate_executor_binder_argument_type<R(&)(A1, A2)>
- {
- typedef A1 first_argument_type;
- typedef A2 second_argument_type;
- };
- }
- template <typename T, typename Executor>
- class immediate_executor_binder
- #if !defined(GENERATING_DOCUMENTATION)
- : public detail::immediate_executor_binder_result_type<T>,
- public detail::immediate_executor_binder_argument_type<T>,
- public detail::immediate_executor_binder_argument_types<T>
- #endif
- {
- public:
-
- typedef T target_type;
-
- typedef Executor immediate_executor_type;
- #if defined(GENERATING_DOCUMENTATION)
-
-
- typedef see_below result_type;
-
-
- typedef see_below argument_type;
-
-
- typedef see_below first_argument_type;
-
-
- typedef see_below second_argument_type;
- #endif
-
-
- template <typename U>
- immediate_executor_binder(const immediate_executor_type& e,
- U&& u)
- : executor_(e),
- target_(static_cast<U&&>(u))
- {
- }
-
- immediate_executor_binder(const immediate_executor_binder& other)
- : executor_(other.get_immediate_executor()),
- target_(other.get())
- {
- }
-
- immediate_executor_binder(const immediate_executor_type& e,
- const immediate_executor_binder& other)
- : executor_(e),
- target_(other.get())
- {
- }
-
-
- template <typename U, typename OtherExecutor>
- immediate_executor_binder(
- const immediate_executor_binder<U, OtherExecutor>& other,
- constraint_t<is_constructible<Executor, OtherExecutor>::value> = 0,
- constraint_t<is_constructible<T, U>::value> = 0)
- : executor_(other.get_immediate_executor()),
- target_(other.get())
- {
- }
-
-
-
- template <typename U, typename OtherExecutor>
- immediate_executor_binder(const immediate_executor_type& e,
- const immediate_executor_binder<U, OtherExecutor>& other,
- constraint_t<is_constructible<T, U>::value> = 0)
- : executor_(e),
- target_(other.get())
- {
- }
-
- immediate_executor_binder(immediate_executor_binder&& other)
- : executor_(static_cast<immediate_executor_type&&>(
- other.get_immediate_executor())),
- target_(static_cast<T&&>(other.get()))
- {
- }
-
-
- immediate_executor_binder(const immediate_executor_type& e,
- immediate_executor_binder&& other)
- : executor_(e),
- target_(static_cast<T&&>(other.get()))
- {
- }
-
- template <typename U, typename OtherExecutor>
- immediate_executor_binder(
- immediate_executor_binder<U, OtherExecutor>&& other,
- constraint_t<is_constructible<Executor, OtherExecutor>::value> = 0,
- constraint_t<is_constructible<T, U>::value> = 0)
- : executor_(static_cast<OtherExecutor&&>(
- other.get_immediate_executor())),
- target_(static_cast<U&&>(other.get()))
- {
- }
-
-
- template <typename U, typename OtherExecutor>
- immediate_executor_binder(const immediate_executor_type& e,
- immediate_executor_binder<U, OtherExecutor>&& other,
- constraint_t<is_constructible<T, U>::value> = 0)
- : executor_(e),
- target_(static_cast<U&&>(other.get()))
- {
- }
-
- ~immediate_executor_binder()
- {
- }
-
- target_type& get() noexcept
- {
- return target_;
- }
-
- const target_type& get() const noexcept
- {
- return target_;
- }
-
- immediate_executor_type get_immediate_executor() const noexcept
- {
- return executor_;
- }
-
- template <typename... Args>
- result_of_t<T(Args...)> operator()(Args&&... args)
- {
- return target_(static_cast<Args&&>(args)...);
- }
-
- template <typename... Args>
- result_of_t<T(Args...)> operator()(Args&&... args) const
- {
- return target_(static_cast<Args&&>(args)...);
- }
- private:
- Executor executor_;
- T target_;
- };
- template <typename Executor>
- struct partial_immediate_executor_binder
- {
-
- explicit partial_immediate_executor_binder(const Executor& ex)
- : executor_(ex)
- {
- }
-
-
- template <typename CompletionToken>
- BOOST_ASIO_NODISCARD inline
- constexpr immediate_executor_binder<decay_t<CompletionToken>, Executor>
- operator()(CompletionToken&& completion_token) const
- {
- return immediate_executor_binder<decay_t<CompletionToken>, Executor>(
- static_cast<CompletionToken&&>(completion_token), executor_);
- }
- Executor executor_;
- };
- template <typename Executor>
- BOOST_ASIO_NODISCARD inline partial_immediate_executor_binder<Executor>
- bind_immediate_executor(const Executor& ex)
- {
- return partial_immediate_executor_binder<Executor>(ex);
- }
- template <typename Executor, typename T>
- BOOST_ASIO_NODISCARD inline immediate_executor_binder<decay_t<T>, Executor>
- bind_immediate_executor(const Executor& e, T&& t)
- {
- return immediate_executor_binder<
- decay_t<T>, Executor>(
- e, static_cast<T&&>(t));
- }
- #if !defined(GENERATING_DOCUMENTATION)
- namespace detail {
- template <typename TargetAsyncResult, typename Executor, typename = void>
- class immediate_executor_binder_completion_handler_async_result
- {
- public:
- template <typename T>
- explicit immediate_executor_binder_completion_handler_async_result(T&)
- {
- }
- };
- template <typename TargetAsyncResult, typename Executor>
- class immediate_executor_binder_completion_handler_async_result<
- TargetAsyncResult, Executor,
- void_t<
- typename TargetAsyncResult::completion_handler_type
- >>
- {
- private:
- TargetAsyncResult target_;
- public:
- typedef immediate_executor_binder<
- typename TargetAsyncResult::completion_handler_type, Executor>
- completion_handler_type;
- explicit immediate_executor_binder_completion_handler_async_result(
- typename TargetAsyncResult::completion_handler_type& handler)
- : target_(handler)
- {
- }
- auto get() -> decltype(target_.get())
- {
- return target_.get();
- }
- };
- template <typename TargetAsyncResult, typename = void>
- struct immediate_executor_binder_async_result_return_type
- {
- };
- template <typename TargetAsyncResult>
- struct immediate_executor_binder_async_result_return_type<
- TargetAsyncResult,
- void_t<
- typename TargetAsyncResult::return_type
- >>
- {
- typedef typename TargetAsyncResult::return_type return_type;
- };
- }
- template <typename T, typename Executor, typename Signature>
- class async_result<immediate_executor_binder<T, Executor>, Signature> :
- public detail::immediate_executor_binder_completion_handler_async_result<
- async_result<T, Signature>, Executor>,
- public detail::immediate_executor_binder_async_result_return_type<
- async_result<T, Signature>>
- {
- public:
- explicit async_result(immediate_executor_binder<T, Executor>& b)
- : detail::immediate_executor_binder_completion_handler_async_result<
- async_result<T, Signature>, Executor>(b.get())
- {
- }
- template <typename Initiation>
- struct init_wrapper : detail::initiation_base<Initiation>
- {
- using detail::initiation_base<Initiation>::initiation_base;
- template <typename Handler, typename... Args>
- void operator()(Handler&& handler, const Executor& e, Args&&... args) &&
- {
- static_cast<Initiation&&>(*this)(
- immediate_executor_binder<
- decay_t<Handler>, Executor>(
- e, static_cast<Handler&&>(handler)),
- static_cast<Args&&>(args)...);
- }
- template <typename Handler, typename... Args>
- void operator()(Handler&& handler,
- const Executor& e, Args&&... args) const &
- {
- static_cast<const Initiation&>(*this)(
- immediate_executor_binder<
- decay_t<Handler>, Executor>(
- e, static_cast<Handler&&>(handler)),
- static_cast<Args&&>(args)...);
- }
- };
- template <typename Initiation, typename RawCompletionToken, typename... Args>
- static auto initiate(Initiation&& initiation,
- RawCompletionToken&& token, Args&&... args)
- -> decltype(
- async_initiate<
- conditional_t<
- is_const<remove_reference_t<RawCompletionToken>>::value, const T, T>,
- Signature>(
- declval<init_wrapper<decay_t<Initiation>>>(),
- token.get(), token.get_immediate_executor(),
- static_cast<Args&&>(args)...))
- {
- return async_initiate<
- conditional_t<
- is_const<remove_reference_t<RawCompletionToken>>::value, const T, T>,
- Signature>(
- init_wrapper<decay_t<Initiation>>(
- static_cast<Initiation&&>(initiation)),
- token.get(), token.get_immediate_executor(),
- static_cast<Args&&>(args)...);
- }
- private:
- async_result(const async_result&) = delete;
- async_result& operator=(const async_result&) = delete;
- async_result<T, Signature> target_;
- };
- template <typename Executor, typename... Signatures>
- struct async_result<partial_immediate_executor_binder<Executor>, Signatures...>
- {
- template <typename Initiation, typename RawCompletionToken, typename... Args>
- static auto initiate(Initiation&& initiation,
- RawCompletionToken&& token, Args&&... args)
- -> decltype(
- async_initiate<Signatures...>(
- static_cast<Initiation&&>(initiation),
- immediate_executor_binder<
- default_completion_token_t<associated_executor_t<Initiation>>,
- Executor>(token.executor_,
- default_completion_token_t<associated_executor_t<Initiation>>{}),
- static_cast<Args&&>(args)...))
- {
- return async_initiate<Signatures...>(
- static_cast<Initiation&&>(initiation),
- immediate_executor_binder<
- default_completion_token_t<associated_executor_t<Initiation>>,
- Executor>(token.executor_,
- default_completion_token_t<associated_executor_t<Initiation>>{}),
- static_cast<Args&&>(args)...);
- }
- };
- template <template <typename, typename> class Associator,
- typename T, typename Executor, typename DefaultCandidate>
- struct associator<Associator,
- immediate_executor_binder<T, Executor>,
- DefaultCandidate>
- : Associator<T, DefaultCandidate>
- {
- static typename Associator<T, DefaultCandidate>::type get(
- const immediate_executor_binder<T, Executor>& b) noexcept
- {
- return Associator<T, DefaultCandidate>::get(b.get());
- }
- static auto get(const immediate_executor_binder<T, Executor>& b,
- const DefaultCandidate& c) noexcept
- -> decltype(Associator<T, DefaultCandidate>::get(b.get(), c))
- {
- return Associator<T, DefaultCandidate>::get(b.get(), c);
- }
- };
- template <typename T, typename Executor, typename Executor1>
- struct associated_immediate_executor<
- immediate_executor_binder<T, Executor>,
- Executor1>
- {
- typedef Executor type;
- static auto get(const immediate_executor_binder<T, Executor>& b,
- const Executor1& = Executor1()) noexcept
- -> decltype(b.get_immediate_executor())
- {
- return b.get_immediate_executor();
- }
- };
- #endif
- }
- }
- #include <boost/asio/detail/pop_options.hpp>
- #endif
|