Clementine
associated_executor.hpp
1 //
2 // associated_executor.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2020 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 //
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 //
10 
11 #ifndef ASIO_ASSOCIATED_EXECUTOR_HPP
12 #define ASIO_ASSOCIATED_EXECUTOR_HPP
13 
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17 
18 #include "asio/detail/config.hpp"
19 #include "asio/detail/type_traits.hpp"
20 #include "asio/execution/executor.hpp"
21 #include "asio/is_executor.hpp"
22 #include "asio/system_executor.hpp"
23 
24 #include "asio/detail/push_options.hpp"
25 
26 namespace asio {
27 namespace detail {
28 
29 template <typename T, typename E, typename = void>
31 {
32  typedef void asio_associated_executor_is_unspecialised;
33 
34  typedef E type;
35 
36  static type get(const T&, const E& e = E()) ASIO_NOEXCEPT
37  {
38  return e;
39  }
40 };
41 
42 template <typename T, typename E>
44  typename void_type<typename T::executor_type>::type>
45 {
46  typedef typename T::executor_type type;
47 
48  static type get(const T& t, const E& = E()) ASIO_NOEXCEPT
49  {
50  return t.get_executor();
51  }
52 };
53 
54 } // namespace detail
55 
57 
75 template <typename T, typename Executor = system_executor>
77 #if !defined(GENERATING_DOCUMENTATION)
79 #endif // !defined(GENERATING_DOCUMENTATION)
80 {
81 #if defined(GENERATING_DOCUMENTATION)
82  typedef see_below type;
85 
88  static type get(const T& t,
89  const Executor& ex = Executor()) ASIO_NOEXCEPT;
90 #endif // defined(GENERATING_DOCUMENTATION)
91 };
92 
94 
97 template <typename T>
98 inline typename associated_executor<T>::type
99 get_associated_executor(const T& t) ASIO_NOEXCEPT
100 {
101  return associated_executor<T>::get(t);
102 }
103 
105 
108 template <typename T, typename Executor>
109 inline typename associated_executor<T, Executor>::type
110 get_associated_executor(const T& t, const Executor& ex,
111  typename enable_if<
113  >::type* = 0) ASIO_NOEXCEPT
114 {
116 }
117 
119 
123 template <typename T, typename ExecutionContext>
124 inline typename associated_executor<T,
125  typename ExecutionContext::executor_type>::type
126 get_associated_executor(const T& t, ExecutionContext& ctx,
127  typename enable_if<is_convertible<ExecutionContext&,
128  execution_context&>::value>::type* = 0) ASIO_NOEXCEPT
129 {
130  return associated_executor<T,
131  typename ExecutionContext::executor_type>::get(t, ctx.get_executor());
132 }
133 
134 #if defined(ASIO_HAS_ALIAS_TEMPLATES)
135 
136 template <typename T, typename Executor = system_executor>
137 using associated_executor_t = typename associated_executor<T, Executor>::type;
138 
139 #endif // defined(ASIO_HAS_ALIAS_TEMPLATES)
140 
141 namespace detail {
142 
143 template <typename T, typename E, typename = void>
145 {
146 };
147 
148 template <typename T, typename E>
150  typename enable_if<
151  is_same<
152  typename associated_executor<T,
153  E>::asio_associated_executor_is_unspecialised,
154  void
155  >::value
156  >::type>
157 {
158  typedef void asio_associated_executor_is_unspecialised;
159 };
160 
161 } // namespace detail
162 } // namespace asio
163 
164 #include "asio/detail/pop_options.hpp"
165 
166 #endif // ASIO_ASSOCIATED_EXECUTOR_HPP
Definition: type_traits.hpp:135
Definition: associated_executor.hpp:30
A context for function object execution.
Definition: execution_context.hpp:105
Definition: chrono.h:284
Definition: type_traits.hpp:97
The is_executor trait detects whether a type T meets the Executor type requirements.
Definition: is_executor.hpp:33
Traits type used to obtain the executor associated with an object.
Definition: associated_executor.hpp:76
Definition: associated_executor.hpp:144
Definition: any_io_executor.hpp:28
The is_executor trait detects whether a type T satisfies the execution::executor concept.
Definition: executor.hpp:109