Debian Codegraph @

libstdc++-v3/include/pstl/glue_memory_impl.h

raw
1 // -*- C++ -*-
2 //===-- glue_memory_impl.h ------------------------------------------------===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef _PSTL_GLUE_MEMORY_IMPL_H
11 #define _PSTL_GLUE_MEMORY_IMPL_H
12
13 #include "utils.h"
14 #include "algorithm_fwd.h"
15
16 #include "execution_impl.h"
17
18 namespace std
19 {
20
21 // [uninitialized.copy]
22
23 template <class _ExecutionPolicy, class _InputIterator, class _ForwardIterator>
24 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
25 uninitialized_copy(_ExecutionPolicy&& __exec, _InputIterator __first, _InputIterator __last, _ForwardIterator __result)
26 {
27 typedef typename iterator_traits<_InputIterator>::value_type _ValueType1;
28 typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType2;
29 typedef typename iterator_traits<_InputIterator>::reference _ReferenceType1;
30 typedef typename iterator_traits<_ForwardIterator>::reference _ReferenceType2;
31
32 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __result);
33
34 using __is_vector = typename decltype(__dispatch_tag)::__is_vector;
35
36 return __pstl::__internal::__invoke_if_else(
37 std::conjunction<std::is_trivially_copyable<_ValueType1>, std::is_trivially_default_constructible<_ValueType1>,
38 std::is_trivially_copyable<_ValueType2>, std::is_trivially_default_constructible<_ValueType2>>(),
39 [&]()
40 {
41 return __pstl::__internal::__pattern_walk2_brick(
42 __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last, __result,
43 [](_InputIterator __begin, _InputIterator __end, _ForwardIterator __res)
44 { return __pstl::__internal::__brick_copy(__begin, __end, __res, __is_vector{}); });
45 },
46 [&]()
47 {
48 return __pstl::__internal::__pattern_walk2(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
49 __last, __result,
50 [](_ReferenceType1 __val1, _ReferenceType2 __val2)
51 { ::new (std::addressof(__val2)) _ValueType2(__val1); });
52 });
53 }
54
55 template <class _ExecutionPolicy, class _InputIterator, class _Size, class _ForwardIterator>
56 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
57 uninitialized_copy_n(_ExecutionPolicy&& __exec, _InputIterator __first, _Size __n, _ForwardIterator __result)
58 {
59 typedef typename iterator_traits<_InputIterator>::value_type _ValueType1;
60 typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType2;
61 typedef typename iterator_traits<_InputIterator>::reference _ReferenceType1;
62 typedef typename iterator_traits<_ForwardIterator>::reference _ReferenceType2;
63
64 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __result);
65
66 using __is_vector = typename decltype(__dispatch_tag)::__is_vector;
67
68 return __pstl::__internal::__invoke_if_else(
69 std::conjunction<std::is_trivially_copyable<_ValueType1>, std::is_trivially_default_constructible<_ValueType1>,
70 std::is_trivially_copyable<_ValueType2>, std::is_trivially_default_constructible<_ValueType2>>(),
71 [&]()
72 {
73 return __pstl::__internal::__pattern_walk2_brick_n(
74 __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __n, __result,
75 [](_InputIterator __begin, _Size __sz, _ForwardIterator __res)
76 { return __pstl::__internal::__brick_copy_n(__begin, __sz, __res, __is_vector{}); });
77 },
78 [&]()
79 {
80 return __pstl::__internal::__pattern_walk2_n(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec),
81 __first, __n, __result,
82 [](_ReferenceType1 __val1, _ReferenceType2 __val2)
83 { ::new (std::addressof(__val2)) _ValueType2(__val1); });
84 });
85 }
86
87 // [uninitialized.move]
88
89 template <class _ExecutionPolicy, class _InputIterator, class _ForwardIterator>
90 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
91 uninitialized_move(_ExecutionPolicy&& __exec, _InputIterator __first, _InputIterator __last, _ForwardIterator __result)
92 {
93 typedef typename iterator_traits<_InputIterator>::value_type _ValueType1;
94 typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType2;
95 typedef typename iterator_traits<_InputIterator>::reference _ReferenceType1;
96 typedef typename iterator_traits<_ForwardIterator>::reference _ReferenceType2;
97
98 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __result);
99
100 using __is_vector = typename decltype(__dispatch_tag)::__is_vector;
101
102 return __pstl::__internal::__invoke_if_else(
103 std::conjunction<std::is_trivially_copyable<_ValueType1>, std::is_trivially_default_constructible<_ValueType1>,
104 std::is_trivially_copyable<_ValueType2>, std::is_trivially_default_constructible<_ValueType2>>(),
105 [&]()
106 {
107 return __pstl::__internal::__pattern_walk2_brick(
108 __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last, __result,
109 [](_InputIterator __begin, _InputIterator __end, _ForwardIterator __res)
110 { return __pstl::__internal::__brick_copy(__begin, __end, __res, __is_vector{}); });
111 },
112 [&]()
113 {
114 return __pstl::__internal::__pattern_walk2(
115 __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last, __result,
116 [](_ReferenceType1 __val1, _ReferenceType2 __val2)
117 { ::new (std::addressof(__val2)) _ValueType2(std::move(__val1)); });
118 });
119 }
120
121 template <class _ExecutionPolicy, class _InputIterator, class _Size, class _ForwardIterator>
122 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
123 uninitialized_move_n(_ExecutionPolicy&& __exec, _InputIterator __first, _Size __n, _ForwardIterator __result)
124 {
125 typedef typename iterator_traits<_InputIterator>::value_type _ValueType1;
126 typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType2;
127 typedef typename iterator_traits<_InputIterator>::reference _ReferenceType1;
128 typedef typename iterator_traits<_ForwardIterator>::reference _ReferenceType2;
129
130 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __result);
131
132 using __is_vector = typename decltype(__dispatch_tag)::__is_vector;
133
134 return __pstl::__internal::__invoke_if_else(
135 std::conjunction<std::is_trivially_copyable<_ValueType1>, std::is_trivially_default_constructible<_ValueType1>,
136 std::is_trivially_copyable<_ValueType2>, std::is_trivially_default_constructible<_ValueType2>>(),
137 [&]()
138 {
139 return __pstl::__internal::__pattern_walk2_brick_n(
140 __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __n, __result,
141 [](_InputIterator __begin, _Size __sz, _ForwardIterator __res)
142 { return __pstl::__internal::__brick_copy_n(__begin, __sz, __res, __is_vector{}); });
143 },
144 [&]()
145 {
146 return __pstl::__internal::__pattern_walk2_n(
147 __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __n, __result,
148 [](_ReferenceType1 __val1, _ReferenceType2 __val2)
149 { ::new (std::addressof(__val2)) _ValueType2(std::move(__val1)); });
150 });
151 }
152
153 // [uninitialized.fill]
154
155 template <class _ExecutionPolicy, class _ForwardIterator, class _Tp>
156 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
157 uninitialized_fill(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
158 {
159 typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
160 typedef typename iterator_traits<_ForwardIterator>::reference _ReferenceType;
161
162 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
163
164 using __is_vector = typename decltype(__dispatch_tag)::__is_vector;
165
166 __pstl::__internal::__invoke_if_else(
167 std::is_arithmetic<_ValueType>(),
168 [&]()
169 {
170 __pstl::__internal::__pattern_walk_brick(
171 __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
172 [&__value](_ForwardIterator __begin, _ForwardIterator __end)
173 { __pstl::__internal::__brick_fill(__begin, __end, _ValueType(__value), __is_vector{}); });
174 },
175 [&]()
176 {
177 __pstl::__internal::__pattern_walk1(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
178 [&__value](_ReferenceType __val)
179 { ::new (std::addressof(__val)) _ValueType(__value); });
180 });
181 }
182
183 template <class _ExecutionPolicy, class _ForwardIterator, class _Size, class _Tp>
184 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
185 uninitialized_fill_n(_ExecutionPolicy&& __exec, _ForwardIterator __first, _Size __n, const _Tp& __value)
186 {
187 typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
188 typedef typename iterator_traits<_ForwardIterator>::reference _ReferenceType;
189
190 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
191
192 using __is_vector = typename decltype(__dispatch_tag)::__is_vector;
193
194 return __pstl::__internal::__invoke_if_else(
195 std::is_arithmetic<_ValueType>(),
196 [&]()
197 {
198 return __pstl::__internal::__pattern_walk_brick_n(
199 __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __n,
200 [&__value](_ForwardIterator __begin, _Size __count)
201 { return __pstl::__internal::__brick_fill_n(__begin, __count, _ValueType(__value), __is_vector{}); });
202 },
203 [&]()
204 {
205 return __pstl::__internal::__pattern_walk1_n(
206 __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __n,
207 [&__value](_ReferenceType __val) { ::new (std::addressof(__val)) _ValueType(__value); });
208 });
209 }
210
211 // [specialized.destroy]
212
213 template <class _ExecutionPolicy, class _ForwardIterator>
214 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
215 destroy(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last)
216 {
217 typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
218 typedef typename iterator_traits<_ForwardIterator>::reference _ReferenceType;
219
220 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
221
222 __pstl::__internal::__invoke_if_not(std::is_trivially_destructible<_ValueType>(),
223 [&]()
224 {
225 __pstl::__internal::__pattern_walk1(
226 __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
227 [](_ReferenceType __val) { __val.~_ValueType(); });
228 });
229 }
230
231 template <class _ExecutionPolicy, class _ForwardIterator, class _Size>
232 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
233 destroy_n(_ExecutionPolicy&& __exec, _ForwardIterator __first, _Size __n)
234 {
235 typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
236 typedef typename iterator_traits<_ForwardIterator>::reference _ReferenceType;
237
238 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
239
240 return __pstl::__internal::__invoke_if_else(
241 std::is_trivially_destructible<_ValueType>(), [&]() { return std::next(__first, __n); },
242 [&]()
243 {
244 return __pstl::__internal::__pattern_walk1_n(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec),
245 __first, __n,
246 [](_ReferenceType __val) { __val.~_ValueType(); });
247 });
248 }
249
250 // [uninitialized.construct.default]
251
252 template <class _ExecutionPolicy, class _ForwardIterator>
253 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
254 uninitialized_default_construct(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last)
255 {
256 typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
257 typedef typename iterator_traits<_ForwardIterator>::reference _ReferenceType;
258
259 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
260
261 __pstl::__internal::__invoke_if_not(std::conjunction<std::is_trivially_copyable<_ValueType>, std::is_trivially_default_constructible<_ValueType>>(),
262 [&]()
263 {
264 __pstl::__internal::__pattern_walk1(
265 __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
266 [](_ReferenceType __val) { ::new (std::addressof(__val)) _ValueType; });
267 });
268 }
269
270 template <class _ExecutionPolicy, class _ForwardIterator, class _Size>
271 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
272 uninitialized_default_construct_n(_ExecutionPolicy&& __exec, _ForwardIterator __first, _Size __n)
273 {
274 typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
275 typedef typename iterator_traits<_ForwardIterator>::reference _ReferenceType;
276
277 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
278
279 return __pstl::__internal::__invoke_if_else(
280 std::conjunction<std::is_trivially_copyable<_ValueType>, std::is_trivially_default_constructible<_ValueType>>(),
281 [&]() { return std::next(__first, __n); },
282 [&]()
283 {
284 return __pstl::__internal::__pattern_walk1_n(
285 __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __n,
286 [](_ReferenceType __val) { ::new (std::addressof(__val)) _ValueType; });
287 });
288 }
289
290 // [uninitialized.construct.value]
291
292 template <class _ExecutionPolicy, class _ForwardIterator>
293 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
294 uninitialized_value_construct(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last)
295 {
296 typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
297 typedef typename iterator_traits<_ForwardIterator>::reference _ReferenceType;
298
299 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
300
301 using __is_vector = typename decltype(__dispatch_tag)::__is_vector;
302
303 __pstl::__internal::__invoke_if_else(
304 std::conjunction<std::is_trivially_copyable<_ValueType>, std::is_trivially_default_constructible<_ValueType>>(),
305 [&]()
306 {
307 __pstl::__internal::__pattern_walk_brick(
308 __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
309 [](_ForwardIterator __begin, _ForwardIterator __end)
310 { __pstl::__internal::__brick_fill(__begin, __end, _ValueType(), __is_vector{}); });
311 },
312 [&]()
313 {
314 __pstl::__internal::__pattern_walk1(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
315 [](_ReferenceType __val)
316 { ::new (std::addressof(__val)) _ValueType(); });
317 });
318 }
319
320 template <class _ExecutionPolicy, class _ForwardIterator, class _Size>
321 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
322 uninitialized_value_construct_n(_ExecutionPolicy&& __exec, _ForwardIterator __first, _Size __n)
323 {
324 typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
325 typedef typename iterator_traits<_ForwardIterator>::reference _ReferenceType;
326
327 auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
328
329 using __is_vector = typename decltype(__dispatch_tag)::__is_vector;
330
331 return __pstl::__internal::__invoke_if_else(
332 std::conjunction<std::is_trivially_copyable<_ValueType>, std::is_trivially_default_constructible<_ValueType>>(),
333 [&]()
334 {
335 return __pstl::__internal::__pattern_walk_brick_n(
336 __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __n,
337 [](_ForwardIterator __begin, _Size __count)
338 { return __pstl::__internal::__brick_fill_n(__begin, __count, _ValueType(), __is_vector{}); });
339 },
340 [&]()
341 {
342 return __pstl::__internal::__pattern_walk1_n(
343 __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __n,
344 [](_ReferenceType __val) { ::new (std::addressof(__val)) _ValueType(); });
345 });
346 }
347
348 } // namespace std
349
350 #endif /* _PSTL_GLUE_MEMORY_IMPL_H */