Clementine
allocator.hpp
1 //
2 // execution/allocator.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_EXECUTION_ALLOCATOR_HPP
12 #define ASIO_EXECUTION_ALLOCATOR_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/execution/scheduler.hpp"
22 #include "asio/execution/sender.hpp"
23 #include "asio/is_applicable_property.hpp"
24 #include "asio/traits/query_static_constexpr_member.hpp"
25 #include "asio/traits/static_query.hpp"
26 
27 #include "asio/detail/push_options.hpp"
28 
29 namespace asio {
30 
31 #if defined(GENERATING_DOCUMENTATION)
32 
33 namespace execution {
34 
37 template <typename ProtoAllocator>
38 struct allocator_t
39 {
41  template <typename T>
42  static constexpr bool is_applicable_property_v =
43  is_executor_v<T> || is_sender_v<T> || is_scheduler_v<T>;
44 
46  static constexpr bool is_requirable = true;
47 
49  static constexpr bool is_preferable = true;
50 
52  constexpr allocator_t();
53 
55 
58  constexpr ProtoAllocator value() const;
59 
61 
64  template <typename OtherAllocator>
65  allocator_t<OtherAllocator operator()(const OtherAllocator& a);
66 };
67 
69 constexpr allocator_t<void> allocator;
70 
71 } // namespace execution
72 
73 #else // defined(GENERATING_DOCUMENTATION)
74 
75 namespace execution {
76 
77 template <typename ProtoAllocator>
79 {
80 #if defined(ASIO_HAS_VARIABLE_TEMPLATES)
81  template <typename T>
82  ASIO_STATIC_CONSTEXPR(bool,
83  is_applicable_property_v = is_executor<T>::value
85 #endif // defined(ASIO_HAS_VARIABLE_TEMPLATES)
86 
87  ASIO_STATIC_CONSTEXPR(bool, is_requirable = true);
88  ASIO_STATIC_CONSTEXPR(bool, is_preferable = true);
89 
90 #if defined(ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
91  && defined(ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
92  template <typename T>
93  static ASIO_CONSTEXPR
95  static_query()
96  ASIO_NOEXCEPT_IF((
98  {
100  }
101 
102  template <typename E, typename T = decltype(allocator_t::static_query<E>())>
103  static ASIO_CONSTEXPR const T static_query_v
104  = allocator_t::static_query<E>();
105 #endif // defined(ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
106  // && defined(ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
107 
108  ASIO_CONSTEXPR ProtoAllocator value() const
109  {
110  return a_;
111  }
112 
113 private:
114  friend struct allocator_t<void>;
115 
116  explicit ASIO_CONSTEXPR allocator_t(const ProtoAllocator& a)
117  : a_(a)
118  {
119  }
120 
121  ProtoAllocator a_;
122 };
123 
124 #if defined(ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
125  && defined(ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
126 template <typename ProtoAllocator> template <typename E, typename T>
128 #endif // defined(ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
129  // && defined(ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
130 
131 template <>
132 struct allocator_t<void>
133 {
134 #if defined(ASIO_HAS_VARIABLE_TEMPLATES)
135  template <typename T>
136  ASIO_STATIC_CONSTEXPR(bool,
137  is_applicable_property_v = is_executor<T>::value
139 #endif // defined(ASIO_HAS_VARIABLE_TEMPLATES)
140 
141  ASIO_STATIC_CONSTEXPR(bool, is_requirable = true);
142  ASIO_STATIC_CONSTEXPR(bool, is_preferable = true);
143 
144  ASIO_CONSTEXPR allocator_t()
145  {
146  }
147 
148 #if defined(ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
149  && defined(ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
150  template <typename T>
151  static ASIO_CONSTEXPR
153  static_query()
154  ASIO_NOEXCEPT_IF((
156  {
158  }
159 
160  template <typename E, typename T = decltype(allocator_t::static_query<E>())>
161  static ASIO_CONSTEXPR const T static_query_v
162  = allocator_t::static_query<E>();
163 #endif // defined(ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
164  // && defined(ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
165 
166  template <typename OtherProtoAllocator>
167  ASIO_CONSTEXPR allocator_t<OtherProtoAllocator> operator()(
168  const OtherProtoAllocator& a) const
169  {
171  }
172 };
173 
174 #if defined(ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
175  && defined(ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
176 template <typename E, typename T>
178 #endif // defined(ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
179  // && defined(ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
180 
181 #if defined(ASIO_HAS_CONSTEXPR) || defined(GENERATING_DOCUMENTATION)
182 constexpr allocator_t<void> allocator;
183 #else // defined(ASIO_HAS_CONSTEXPR) || defined(GENERATING_DOCUMENTATION)
184 template <typename T>
186 {
187  static allocator_t<T> instance;
188 };
189 
190 template <typename T>
192 
193 namespace {
194 static const allocator_t<void>& allocator = allocator_instance<void>::instance;
195 } // namespace
196 #endif
197 
198 } // namespace execution
199 
200 #if !defined(ASIO_HAS_VARIABLE_TEMPLATES)
201 
202 template <typename T, typename ProtoAllocator>
203 struct is_applicable_property<T, execution::allocator_t<ProtoAllocator> >
204  : integral_constant<bool,
205  execution::is_executor<T>::value
206  || execution::is_sender<T>::value
207  || execution::is_scheduler<T>::value>
208 {
209 };
210 
211 #endif // !defined(ASIO_HAS_VARIABLE_TEMPLATES)
212 
213 namespace traits {
214 
215 #if !defined(ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
216  || !defined(ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
217 
218 template <typename T, typename ProtoAllocator>
219 struct static_query<T, execution::allocator_t<ProtoAllocator>,
220  typename enable_if<
221  traits::query_static_constexpr_member<T,
222  execution::allocator_t<ProtoAllocator> >::is_valid
223  >::type>
224 {
225  ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
226  ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
227 
228  typedef typename traits::query_static_constexpr_member<T,
229  execution::allocator_t<ProtoAllocator> >::result_type result_type;
230 
231  static ASIO_CONSTEXPR result_type value()
232  {
235  }
236 };
237 
238 #endif // !defined(ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
239  // || !defined(ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
240 
241 } // namespace traits
242 
243 #endif // defined(GENERATING_DOCUMENTATION)
244 
245 } // namespace asio
246 
247 #include "asio/detail/pop_options.hpp"
248 
249 #endif // ASIO_EXECUTION_ALLOCATOR_HPP
Definition: allocator.hpp:185
The is_scheduler trait detects whether a type T satisfies the execution::scheduler concept...
Definition: scheduler.hpp:48
The is_sender trait detects whether a type T satisfies the execution::sender concept.
Definition: sender.hpp:183
Definition: allocator.hpp:17
Definition: static_query.hpp:42
Definition: allocator.hpp:78
Definition: type_traits.hpp:97
Definition: query_static_constexpr_member.hpp:42
Definition: handler_work.hpp:37
Definition: is_applicable_property.hpp:46
Definition: allocator.hpp:132
Definition: any_io_executor.hpp:28
The is_executor trait detects whether a type T satisfies the execution::executor concept.
Definition: executor.hpp:109