summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/asio/include/asio/associated_executor.hpp
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/asio/include/asio/associated_executor.hpp')
-rw-r--r--3rdparty/asio/include/asio/associated_executor.hpp120
1 files changed, 100 insertions, 20 deletions
diff --git a/3rdparty/asio/include/asio/associated_executor.hpp b/3rdparty/asio/include/asio/associated_executor.hpp
index 74603c593f0..1e62e37a12e 100644
--- a/3rdparty/asio/include/asio/associated_executor.hpp
+++ b/3rdparty/asio/include/asio/associated_executor.hpp
@@ -2,7 +2,7 @@
// associated_executor.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,27 +16,42 @@
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include "asio/detail/config.hpp"
+#include "asio/associator.hpp"
+#include "asio/detail/functional.hpp"
#include "asio/detail/type_traits.hpp"
+#include "asio/execution/executor.hpp"
#include "asio/is_executor.hpp"
#include "asio/system_executor.hpp"
#include "asio/detail/push_options.hpp"
namespace asio {
+
+template <typename T, typename Executor>
+struct associated_executor;
+
namespace detail {
-template <typename>
-struct associated_executor_check
+template <typename T, typename = void>
+struct has_executor_type : false_type
{
- typedef void type;
};
-template <typename T, typename E, typename = void>
+template <typename T>
+struct has_executor_type<T,
+ typename void_type<typename T::executor_type>::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&, const E& e) ASIO_NOEXCEPT
+ static type get(const T&, const E& e = E()) ASIO_NOEXCEPT
{
return e;
}
@@ -44,16 +59,27 @@ struct associated_executor_impl
template <typename T, typename E>
struct associated_executor_impl<T, E,
- typename associated_executor_check<typename T::executor_type>::type>
+ typename void_type<typename T::executor_type>::type>
{
typedef typename T::executor_type type;
- static type get(const T& t, const E&) ASIO_NOEXCEPT
+ static type get(const T& t, const E& = E()) ASIO_NOEXCEPT
{
return t.get_executor();
}
};
+template <typename T, typename E>
+struct associated_executor_impl<T, E,
+ typename enable_if<
+ !has_executor_type<T>::value
+ >::type,
+ typename void_type<
+ typename associator<associated_executor, T, E>::type
+ >::type> : associator<associated_executor, T, E>
+{
+};
+
} // namespace detail
/// Traits type used to obtain the executor associated with an object.
@@ -77,22 +103,20 @@ struct associated_executor_impl<T, E,
*/
template <typename T, typename Executor = system_executor>
struct associated_executor
+#if !defined(GENERATING_DOCUMENTATION)
+ : detail::associated_executor_impl<T, Executor>
+#endif // !defined(GENERATING_DOCUMENTATION)
{
+#if defined(GENERATING_DOCUMENTATION)
/// If @c T has a nested type @c executor_type, <tt>T::executor_type</tt>.
/// Otherwise @c Executor.
-#if defined(GENERATING_DOCUMENTATION)
typedef see_below type;
-#else // defined(GENERATING_DOCUMENTATION)
- typedef typename detail::associated_executor_impl<T, Executor>::type type;
-#endif // defined(GENERATING_DOCUMENTATION)
/// If @c T has a nested type @c executor_type, returns
/// <tt>t.get_executor()</tt>. Otherwise returns @c ex.
static type get(const T& t,
- const Executor& ex = Executor()) ASIO_NOEXCEPT
- {
- return detail::associated_executor_impl<T, Executor>::get(t, ex);
- }
+ const Executor& ex = Executor()) ASIO_NOEXCEPT;
+#endif // defined(GENERATING_DOCUMENTATION)
};
/// Helper function to obtain an object's associated executor.
@@ -113,8 +137,9 @@ get_associated_executor(const T& t) ASIO_NOEXCEPT
template <typename T, typename Executor>
inline typename associated_executor<T, Executor>::type
get_associated_executor(const T& t, const Executor& ex,
- typename enable_if<is_executor<
- Executor>::value>::type* = 0) ASIO_NOEXCEPT
+ typename constraint<
+ is_executor<Executor>::value || execution::is_executor<Executor>::value
+ >::type = 0) ASIO_NOEXCEPT
{
return associated_executor<T, Executor>::get(t, ex);
}
@@ -128,13 +153,68 @@ template <typename T, typename ExecutionContext>
inline typename associated_executor<T,
typename ExecutionContext::executor_type>::type
get_associated_executor(const T& t, ExecutionContext& ctx,
- typename enable_if<is_convertible<ExecutionContext&,
- execution_context&>::value>::type* = 0) ASIO_NOEXCEPT
+ typename constraint<is_convertible<ExecutionContext&,
+ execution_context&>::value>::type = 0) ASIO_NOEXCEPT
{
return associated_executor<T,
typename ExecutionContext::executor_type>::get(t, ctx.get_executor());
}
+#if defined(ASIO_HAS_ALIAS_TEMPLATES)
+
+template <typename T, typename Executor = system_executor>
+using associated_executor_t = typename associated_executor<T, Executor>::type;
+
+#endif // defined(ASIO_HAS_ALIAS_TEMPLATES)
+
+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,
+ typename enable_if<
+ is_same<
+ typename associated_executor<T,
+ E>::asio_associated_executor_is_unspecialised,
+ void
+ >::value
+ >::type>
+{
+ typedef void asio_associated_executor_is_unspecialised;
+};
+
+} // namespace detail
+
+#if defined(ASIO_HAS_STD_REFERENCE_WRAPPER) \
+ || defined(GENERATING_DOCUMENTATION)
+
+/// Specialisation of associated_executor for @c std::reference_wrapper.
+template <typename T, typename Executor>
+struct associated_executor<reference_wrapper<T>, Executor>
+#if !defined(GENERATING_DOCUMENTATION)
+ : detail::associated_executor_forwarding_base<T, Executor>
+#endif // !defined(GENERATING_DOCUMENTATION)
+{
+ /// Forwards @c type to the associator specialisation for the unwrapped type
+ /// @c T.
+ typedef typename associated_executor<T, Executor>::type type;
+
+ /// Forwards the request to get the executor to the associator specialisation
+ /// for the unwrapped type @c T.
+ static type get(reference_wrapper<T> t,
+ const Executor& ex = Executor()) ASIO_NOEXCEPT
+ {
+ return associated_executor<T, Executor>::get(t.get(), ex);
+ }
+};
+
+#endif // defined(ASIO_HAS_STD_REFERENCE_WRAPPER)
+ // || defined(GENERATING_DOCUMENTATION)
+
} // namespace asio
#include "asio/detail/pop_options.hpp"