123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- #ifndef BOOST_ASIO_ASSOCIATED_EXECUTOR_HPP
- #define BOOST_ASIO_ASSOCIATED_EXECUTOR_HPP
- #if defined(_MSC_VER) && (_MSC_VER >= 1200)
- # pragma once
- #endif
- #include <boost/asio/detail/config.hpp>
- #include <boost/asio/associator.hpp>
- #include <boost/asio/detail/functional.hpp>
- #include <boost/asio/detail/type_traits.hpp>
- #include <boost/asio/execution/executor.hpp>
- #include <boost/asio/is_executor.hpp>
- #include <boost/asio/system_executor.hpp>
- #include <boost/asio/detail/push_options.hpp>
- namespace boost {
- namespace asio {
- template <typename T, typename Executor>
- struct associated_executor;
- namespace detail {
- template <typename T, typename = void>
- struct has_executor_type : false_type
- {
- };
- template <typename T>
- struct has_executor_type<T, void_t<typename T::executor_type>>
- : true_type
- {
- };
- template <typename T, typename E, typename = void, typename = void>
- struct associated_executor_impl
- {
- typedef void asio_associated_executor_is_unspecialised;
- typedef E type;
- static type get(const T&) noexcept
- {
- return type();
- }
- static const type& get(const T&, const E& e) noexcept
- {
- return e;
- }
- };
- template <typename T, typename E>
- struct associated_executor_impl<T, E, void_t<typename T::executor_type>>
- {
- typedef typename T::executor_type type;
- static auto get(const T& t) noexcept
- -> decltype(t.get_executor())
- {
- return t.get_executor();
- }
- static auto get(const T& t, const E&) noexcept
- -> decltype(t.get_executor())
- {
- return t.get_executor();
- }
- };
- template <typename T, typename E>
- struct associated_executor_impl<T, E,
- enable_if_t<
- !has_executor_type<T>::value
- >,
- void_t<
- typename associator<associated_executor, T, E>::type
- >> : associator<associated_executor, T, E>
- {
- };
- }
- template <typename T, typename Executor = system_executor>
- struct associated_executor
- #if !defined(GENERATING_DOCUMENTATION)
- : detail::associated_executor_impl<T, Executor>
- #endif
- {
- #if defined(GENERATING_DOCUMENTATION)
-
-
- typedef see_below type;
-
-
- static decltype(auto) get(const T& t) noexcept;
-
-
- static decltype(auto) get(const T& t, const Executor& ex) noexcept;
- #endif
- };
- template <typename T>
- BOOST_ASIO_NODISCARD inline typename associated_executor<T>::type
- get_associated_executor(const T& t) noexcept
- {
- return associated_executor<T>::get(t);
- }
- template <typename T, typename Executor>
- BOOST_ASIO_NODISCARD inline auto get_associated_executor(
- const T& t, const Executor& ex,
- constraint_t<
- is_executor<Executor>::value || execution::is_executor<Executor>::value
- > = 0) noexcept
- -> decltype(associated_executor<T, Executor>::get(t, ex))
- {
- return associated_executor<T, Executor>::get(t, ex);
- }
- template <typename T, typename ExecutionContext>
- BOOST_ASIO_NODISCARD inline typename associated_executor<T,
- typename ExecutionContext::executor_type>::type
- get_associated_executor(const T& t, ExecutionContext& ctx,
- constraint_t<is_convertible<ExecutionContext&,
- execution_context&>::value> = 0) noexcept
- {
- return associated_executor<T,
- typename ExecutionContext::executor_type>::get(t, ctx.get_executor());
- }
- template <typename T, typename Executor = system_executor>
- using associated_executor_t = typename associated_executor<T, Executor>::type;
- namespace detail {
- template <typename T, typename E, typename = void>
- struct associated_executor_forwarding_base
- {
- };
- template <typename T, typename E>
- struct associated_executor_forwarding_base<T, E,
- enable_if_t<
- is_same<
- typename associated_executor<T,
- E>::asio_associated_executor_is_unspecialised,
- void
- >::value
- >>
- {
- typedef void asio_associated_executor_is_unspecialised;
- };
- }
- template <typename T, typename Executor>
- struct associated_executor<reference_wrapper<T>, Executor>
- #if !defined(GENERATING_DOCUMENTATION)
- : detail::associated_executor_forwarding_base<T, Executor>
- #endif
- {
-
-
- typedef typename associated_executor<T, Executor>::type type;
-
-
- static type get(reference_wrapper<T> t) noexcept
- {
- return associated_executor<T, Executor>::get(t.get());
- }
-
-
- static auto get(reference_wrapper<T> t, const Executor& ex) noexcept
- -> decltype(associated_executor<T, Executor>::get(t.get(), ex))
- {
- return associated_executor<T, Executor>::get(t.get(), ex);
- }
- };
- }
- }
- #include <boost/asio/detail/pop_options.hpp>
- #endif
|