]>
Commit | Line | Data |
---|---|---|
677aad9c JW |
1 | // <scoped_allocator> -*- C++ -*- |
2 | ||
83ffe9cd | 3 | // Copyright (C) 2011-2023 Free Software Foundation, Inc. |
677aad9c JW |
4 | // |
5 | // This file is part of the GNU ISO C++ Library. This library is free | |
6 | // software; you can redistribute it and/or modify it under the | |
7 | // terms of the GNU General Public License as published by the | |
8 | // Free Software Foundation; either version 3, or (at your option) | |
9 | // any later version. | |
10 | ||
11 | // This library is distributed in the hope that it will be useful, | |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | // GNU General Public License for more details. | |
15 | ||
16 | // Under Section 7 of GPL version 3, you are granted additional | |
17 | // permissions described in the GCC Runtime Library Exception, version | |
18 | // 3.1, as published by the Free Software Foundation. | |
19 | ||
20 | // You should have received a copy of the GNU General Public License and | |
21 | // a copy of the GCC Runtime Library Exception along with this program; | |
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
23 | // <http://www.gnu.org/licenses/>. | |
24 | ||
25 | /** @file include/scoped_allocator | |
26 | * This is a Standard C++ Library header. | |
27 | */ | |
28 | ||
29 | #ifndef _SCOPED_ALLOCATOR | |
30 | #define _SCOPED_ALLOCATOR 1 | |
31 | ||
32 | #pragma GCC system_header | |
33 | ||
734f5023 | 34 | #if __cplusplus < 201103L |
677aad9c JW |
35 | # include <bits/c++0x_warning.h> |
36 | #else | |
37 | ||
677aad9c JW |
38 | #include <tuple> |
39 | #include <bits/alloc_traits.h> | |
b1e7c6fc JW |
40 | #include <bits/stl_pair.h> |
41 | #include <bits/uses_allocator.h> | |
42 | #if __cplusplus > 201703L | |
43 | # include <bits/uses_allocator_args.h> | |
44 | #endif | |
677aad9c JW |
45 | |
46 | namespace std _GLIBCXX_VISIBILITY(default) | |
47 | { | |
48 | _GLIBCXX_BEGIN_NAMESPACE_VERSION | |
49 | ||
677aad9c JW |
50 | /** |
51 | * @addtogroup allocators | |
52 | * @{ | |
53 | */ | |
54 | ||
6963c3b9 JW |
55 | template<typename _OuterAlloc, typename... _InnerAllocs> |
56 | class scoped_allocator_adaptor; | |
57 | ||
c05ab418 JW |
58 | /// @cond undocumented |
59 | ||
677aad9c | 60 | template<typename _Alloc> |
937ec71a JW |
61 | using __outer_allocator_t |
62 | = decltype(std::declval<_Alloc>().outer_allocator()); | |
63 | ||
64 | template<typename _Alloc, typename = void> | |
65 | struct __outermost_type | |
66 | { | |
67 | using type = _Alloc; | |
68 | static type& _S_outermost(_Alloc& __a) { return __a; } | |
69 | }; | |
677aad9c JW |
70 | |
71 | template<typename _Alloc> | |
937ec71a JW |
72 | struct __outermost_type<_Alloc, __void_t<__outer_allocator_t<_Alloc>>> |
73 | : __outermost_type< | |
74 | typename remove_reference<__outer_allocator_t<_Alloc>>::type | |
75 | > | |
76 | { | |
77 | using __base = __outermost_type< | |
78 | typename remove_reference<__outer_allocator_t<_Alloc>>::type | |
79 | >; | |
80 | ||
81 | static typename __base::type& | |
82 | _S_outermost(_Alloc& __a) | |
83 | { return __base::_S_outermost(__a.outer_allocator()); } | |
84 | }; | |
677aad9c | 85 | |
6963c3b9 | 86 | // Implementation of the OUTERMOST pseudofunction |
677aad9c | 87 | template<typename _Alloc> |
937ec71a | 88 | inline typename __outermost_type<_Alloc>::type& |
f885fa89 | 89 | __outermost(_Alloc& __a) |
937ec71a | 90 | { return __outermost_type<_Alloc>::_S_outermost(__a); } |
677aad9c | 91 | |
33ac58d5 | 92 | template<typename...> |
93c66bc6 | 93 | struct __inner_type_impl; |
677aad9c | 94 | |
93c66bc6 BK |
95 | template<typename _Outer> |
96 | struct __inner_type_impl<_Outer> | |
97 | { | |
98 | typedef scoped_allocator_adaptor<_Outer> __type; | |
677aad9c | 99 | |
93c66bc6 BK |
100 | __inner_type_impl() = default; |
101 | __inner_type_impl(const __inner_type_impl&) = default; | |
102 | __inner_type_impl(__inner_type_impl&&) = default; | |
9d8dbe73 JW |
103 | __inner_type_impl& operator=(const __inner_type_impl&) = default; |
104 | __inner_type_impl& operator=(__inner_type_impl&&) = default; | |
33ac58d5 | 105 | |
93c66bc6 BK |
106 | template<typename _Alloc> |
107 | __inner_type_impl(const __inner_type_impl<_Alloc>& __other) | |
108 | { } | |
33ac58d5 | 109 | |
93c66bc6 BK |
110 | template<typename _Alloc> |
111 | __inner_type_impl(__inner_type_impl<_Alloc>&& __other) | |
112 | { } | |
33ac58d5 JW |
113 | |
114 | __type& | |
93c66bc6 | 115 | _M_get(__type* __p) noexcept { return *__p; } |
677aad9c | 116 | |
33ac58d5 | 117 | const __type& |
93c66bc6 | 118 | _M_get(const __type* __p) const noexcept { return *__p; } |
33ac58d5 JW |
119 | |
120 | tuple<> | |
93c66bc6 | 121 | _M_tie() const noexcept { return tuple<>(); } |
33ac58d5 JW |
122 | |
123 | bool | |
93c66bc6 BK |
124 | operator==(const __inner_type_impl&) const noexcept |
125 | { return true; } | |
126 | }; | |
677aad9c | 127 | |
93c66bc6 BK |
128 | template<typename _Outer, typename _InnerHead, typename... _InnerTail> |
129 | struct __inner_type_impl<_Outer, _InnerHead, _InnerTail...> | |
130 | { | |
131 | typedef scoped_allocator_adaptor<_InnerHead, _InnerTail...> __type; | |
33ac58d5 | 132 | |
93c66bc6 BK |
133 | __inner_type_impl() = default; |
134 | __inner_type_impl(const __inner_type_impl&) = default; | |
135 | __inner_type_impl(__inner_type_impl&&) = default; | |
9d8dbe73 JW |
136 | __inner_type_impl& operator=(const __inner_type_impl&) = default; |
137 | __inner_type_impl& operator=(__inner_type_impl&&) = default; | |
33ac58d5 | 138 | |
93c66bc6 BK |
139 | template<typename... _Allocs> |
140 | __inner_type_impl(const __inner_type_impl<_Allocs...>& __other) | |
141 | : _M_inner(__other._M_inner) { } | |
33ac58d5 | 142 | |
93c66bc6 BK |
143 | template<typename... _Allocs> |
144 | __inner_type_impl(__inner_type_impl<_Allocs...>&& __other) | |
145 | : _M_inner(std::move(__other._M_inner)) { } | |
677aad9c | 146 | |
93c66bc6 BK |
147 | template<typename... _Args> |
148 | explicit | |
149 | __inner_type_impl(_Args&&... __args) | |
150 | : _M_inner(std::forward<_Args>(__args)...) { } | |
677aad9c | 151 | |
33ac58d5 | 152 | __type& |
93c66bc6 | 153 | _M_get(void*) noexcept { return _M_inner; } |
33ac58d5 JW |
154 | |
155 | const __type& | |
93c66bc6 | 156 | _M_get(const void*) const noexcept { return _M_inner; } |
33ac58d5 JW |
157 | |
158 | tuple<const _InnerHead&, const _InnerTail&...> | |
93c66bc6 BK |
159 | _M_tie() const noexcept |
160 | { return _M_inner._M_tie(); } | |
33ac58d5 JW |
161 | |
162 | bool | |
93c66bc6 BK |
163 | operator==(const __inner_type_impl& __other) const noexcept |
164 | { return _M_inner == __other._M_inner; } | |
33ac58d5 | 165 | |
93c66bc6 BK |
166 | private: |
167 | template<typename...> friend class __inner_type_impl; | |
168 | template<typename, typename...> friend class scoped_allocator_adaptor; | |
33ac58d5 | 169 | |
93c66bc6 BK |
170 | __type _M_inner; |
171 | }; | |
677aad9c | 172 | |
c05ab418 JW |
173 | /// @endcond |
174 | ||
175 | /// An adaptor to recursively pass an allocator to the objects it constructs | |
677aad9c JW |
176 | template<typename _OuterAlloc, typename... _InnerAllocs> |
177 | class scoped_allocator_adaptor | |
178 | : public _OuterAlloc | |
179 | { | |
180 | typedef allocator_traits<_OuterAlloc> __traits; | |
181 | ||
182 | typedef __inner_type_impl<_OuterAlloc, _InnerAllocs...> __inner_type; | |
183 | __inner_type _M_inner; | |
184 | ||
185 | template<typename _Outer, typename... _Inner> | |
186 | friend class scoped_allocator_adaptor; | |
187 | ||
188 | template<typename...> | |
189 | friend class __inner_type_impl; | |
190 | ||
191 | tuple<const _OuterAlloc&, const _InnerAllocs&...> | |
192 | _M_tie() const noexcept | |
193 | { return std::tuple_cat(std::tie(outer_allocator()), _M_inner._M_tie()); } | |
194 | ||
644b2e4c JW |
195 | template<typename _Alloc> |
196 | using __outermost_alloc_traits | |
937ec71a | 197 | = allocator_traits<typename __outermost_type<_Alloc>::type>; |
33ac58d5 | 198 | |
b1e7c6fc | 199 | #if ! __cpp_lib_make_obj_using_allocator |
677aad9c | 200 | template<typename _Tp, typename... _Args> |
33ac58d5 | 201 | void |
93c66bc6 | 202 | _M_construct(__uses_alloc0, _Tp* __p, _Args&&... __args) |
677aad9c | 203 | { |
644b2e4c JW |
204 | typedef __outermost_alloc_traits<scoped_allocator_adaptor> _O_traits; |
205 | _O_traits::construct(__outermost(*this), __p, | |
206 | std::forward<_Args>(__args)...); | |
677aad9c JW |
207 | } |
208 | ||
209 | typedef __uses_alloc1<typename __inner_type::__type> __uses_alloc1_; | |
210 | typedef __uses_alloc2<typename __inner_type::__type> __uses_alloc2_; | |
211 | ||
212 | template<typename _Tp, typename... _Args> | |
33ac58d5 | 213 | void |
93c66bc6 | 214 | _M_construct(__uses_alloc1_, _Tp* __p, _Args&&... __args) |
677aad9c | 215 | { |
644b2e4c JW |
216 | typedef __outermost_alloc_traits<scoped_allocator_adaptor> _O_traits; |
217 | _O_traits::construct(__outermost(*this), __p, | |
218 | allocator_arg, inner_allocator(), | |
219 | std::forward<_Args>(__args)...); | |
677aad9c JW |
220 | } |
221 | ||
222 | template<typename _Tp, typename... _Args> | |
33ac58d5 | 223 | void |
93c66bc6 | 224 | _M_construct(__uses_alloc2_, _Tp* __p, _Args&&... __args) |
677aad9c | 225 | { |
644b2e4c JW |
226 | typedef __outermost_alloc_traits<scoped_allocator_adaptor> _O_traits; |
227 | _O_traits::construct(__outermost(*this), __p, | |
228 | std::forward<_Args>(__args)..., | |
229 | inner_allocator()); | |
677aad9c | 230 | } |
b1e7c6fc | 231 | #endif // ! make_obj_using_allocator |
677aad9c JW |
232 | |
233 | template<typename _Alloc> | |
234 | static _Alloc | |
235 | _S_select_on_copy(const _Alloc& __a) | |
236 | { | |
237 | typedef allocator_traits<_Alloc> __a_traits; | |
238 | return __a_traits::select_on_container_copy_construction(__a); | |
239 | } | |
240 | ||
049d2893 | 241 | template<std::size_t... _Indices> |
677aad9c JW |
242 | scoped_allocator_adaptor(tuple<const _OuterAlloc&, |
243 | const _InnerAllocs&...> __refs, | |
244 | _Index_tuple<_Indices...>) | |
245 | : _OuterAlloc(_S_select_on_copy(std::get<0>(__refs))), | |
246 | _M_inner(_S_select_on_copy(std::get<_Indices+1>(__refs))...) | |
247 | { } | |
248 | ||
937ec71a JW |
249 | // Used to constrain constructors to disallow invalid conversions. |
250 | template<typename _Alloc> | |
251 | using _Constructible = typename enable_if< | |
252 | is_constructible<_OuterAlloc, _Alloc>::value | |
253 | >::type; | |
254 | ||
05891e9f JW |
255 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
256 | // 2975. Missing case for pair construction in scoped [...] allocators | |
257 | template<typename _Tp> | |
258 | struct __not_pair { using type = void; }; | |
259 | ||
260 | template<typename _Tp, typename _Up> | |
261 | struct __not_pair<pair<_Tp, _Up>> { }; | |
262 | ||
677aad9c JW |
263 | public: |
264 | typedef _OuterAlloc outer_allocator_type; | |
265 | typedef typename __inner_type::__type inner_allocator_type; | |
266 | ||
267 | typedef typename __traits::value_type value_type; | |
268 | typedef typename __traits::size_type size_type; | |
269 | typedef typename __traits::difference_type difference_type; | |
270 | typedef typename __traits::pointer pointer; | |
271 | typedef typename __traits::const_pointer const_pointer; | |
272 | typedef typename __traits::void_pointer void_pointer; | |
273 | typedef typename __traits::const_void_pointer const_void_pointer; | |
274 | ||
a2b5fdcb JW |
275 | typedef typename __or_< |
276 | typename __traits::propagate_on_container_copy_assignment, | |
277 | typename allocator_traits<_InnerAllocs>:: | |
278 | propagate_on_container_copy_assignment...>::type | |
279 | propagate_on_container_copy_assignment; | |
280 | ||
281 | typedef typename __or_< | |
282 | typename __traits::propagate_on_container_move_assignment, | |
283 | typename allocator_traits<_InnerAllocs>:: | |
284 | propagate_on_container_move_assignment...>::type | |
285 | propagate_on_container_move_assignment; | |
286 | ||
287 | typedef typename __or_< | |
288 | typename __traits::propagate_on_container_swap, | |
289 | typename allocator_traits<_InnerAllocs>:: | |
290 | propagate_on_container_swap...>::type | |
291 | propagate_on_container_swap; | |
292 | ||
293 | typedef typename __and_< | |
294 | typename __traits::is_always_equal, | |
295 | typename allocator_traits<_InnerAllocs>::is_always_equal...>::type | |
296 | is_always_equal; | |
677aad9c JW |
297 | |
298 | template <class _Tp> | |
299 | struct rebind | |
300 | { | |
677aad9c | 301 | typedef scoped_allocator_adaptor< |
7579d15b | 302 | typename __traits::template rebind_alloc<_Tp>, |
677aad9c JW |
303 | _InnerAllocs...> other; |
304 | }; | |
305 | ||
306 | scoped_allocator_adaptor() : _OuterAlloc(), _M_inner() { } | |
307 | ||
937ec71a | 308 | template<typename _Outer2, typename = _Constructible<_Outer2>> |
677aad9c JW |
309 | scoped_allocator_adaptor(_Outer2&& __outer, |
310 | const _InnerAllocs&... __inner) | |
311 | : _OuterAlloc(std::forward<_Outer2>(__outer)), | |
312 | _M_inner(__inner...) | |
313 | { } | |
314 | ||
315 | scoped_allocator_adaptor(const scoped_allocator_adaptor& __other) | |
316 | : _OuterAlloc(__other.outer_allocator()), | |
317 | _M_inner(__other._M_inner) | |
318 | { } | |
319 | ||
320 | scoped_allocator_adaptor(scoped_allocator_adaptor&& __other) | |
321 | : _OuterAlloc(std::move(__other.outer_allocator())), | |
322 | _M_inner(std::move(__other._M_inner)) | |
323 | { } | |
324 | ||
937ec71a | 325 | template<typename _Outer2, typename = _Constructible<const _Outer2&>> |
677aad9c JW |
326 | scoped_allocator_adaptor( |
327 | const scoped_allocator_adaptor<_Outer2, _InnerAllocs...>& __other) | |
328 | : _OuterAlloc(__other.outer_allocator()), | |
329 | _M_inner(__other._M_inner) | |
330 | { } | |
331 | ||
937ec71a | 332 | template<typename _Outer2, typename = _Constructible<_Outer2>> |
677aad9c JW |
333 | scoped_allocator_adaptor( |
334 | scoped_allocator_adaptor<_Outer2, _InnerAllocs...>&& __other) | |
335 | : _OuterAlloc(std::move(__other.outer_allocator())), | |
336 | _M_inner(std::move(__other._M_inner)) | |
337 | { } | |
338 | ||
9d8dbe73 JW |
339 | scoped_allocator_adaptor& |
340 | operator=(const scoped_allocator_adaptor&) = default; | |
341 | ||
342 | scoped_allocator_adaptor& | |
343 | operator=(scoped_allocator_adaptor&&) = default; | |
344 | ||
677aad9c JW |
345 | inner_allocator_type& inner_allocator() noexcept |
346 | { return _M_inner._M_get(this); } | |
347 | ||
348 | const inner_allocator_type& inner_allocator() const noexcept | |
349 | { return _M_inner._M_get(this); } | |
350 | ||
351 | outer_allocator_type& outer_allocator() noexcept | |
352 | { return static_cast<_OuterAlloc&>(*this); } | |
353 | ||
354 | const outer_allocator_type& outer_allocator() const noexcept | |
355 | { return static_cast<const _OuterAlloc&>(*this); } | |
356 | ||
d715f554 | 357 | _GLIBCXX_NODISCARD pointer allocate(size_type __n) |
677aad9c JW |
358 | { return __traits::allocate(outer_allocator(), __n); } |
359 | ||
d715f554 | 360 | _GLIBCXX_NODISCARD pointer allocate(size_type __n, const_void_pointer __hint) |
677aad9c JW |
361 | { return __traits::allocate(outer_allocator(), __n, __hint); } |
362 | ||
363 | void deallocate(pointer __p, size_type __n) | |
364 | { return __traits::deallocate(outer_allocator(), __p, __n); } | |
365 | ||
366 | size_type max_size() const | |
367 | { return __traits::max_size(outer_allocator()); } | |
368 | ||
b1e7c6fc | 369 | #if ! __cpp_lib_make_obj_using_allocator |
677aad9c | 370 | template<typename _Tp, typename... _Args> |
05891e9f JW |
371 | typename __not_pair<_Tp>::type |
372 | construct(_Tp* __p, _Args&&... __args) | |
373 | { | |
374 | auto& __inner = inner_allocator(); | |
375 | auto __use_tag | |
b479fbad | 376 | = std::__use_alloc<_Tp, inner_allocator_type, _Args...>(__inner); |
05891e9f JW |
377 | _M_construct(__use_tag, __p, std::forward<_Args>(__args)...); |
378 | } | |
677aad9c | 379 | |
644b2e4c JW |
380 | template<typename _T1, typename _T2, typename... _Args1, |
381 | typename... _Args2> | |
382 | void | |
383 | construct(pair<_T1, _T2>* __p, piecewise_construct_t, | |
384 | tuple<_Args1...> __x, tuple<_Args2...> __y) | |
385 | { | |
1b5dc776 JW |
386 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
387 | // 2203. wrong argument types for piecewise construction | |
644b2e4c JW |
388 | auto& __inner = inner_allocator(); |
389 | auto __x_use_tag | |
b479fbad | 390 | = std::__use_alloc<_T1, inner_allocator_type, _Args1...>(__inner); |
644b2e4c | 391 | auto __y_use_tag |
b479fbad | 392 | = std::__use_alloc<_T2, inner_allocator_type, _Args2...>(__inner); |
a4744f62 JW |
393 | typename _Build_index_tuple<sizeof...(_Args1)>::__type __x_indices; |
394 | typename _Build_index_tuple<sizeof...(_Args2)>::__type __y_indices; | |
644b2e4c JW |
395 | typedef __outermost_alloc_traits<scoped_allocator_adaptor> _O_traits; |
396 | _O_traits::construct(__outermost(*this), __p, piecewise_construct, | |
a4744f62 JW |
397 | _M_construct_p(__x_use_tag, __x_indices, __x), |
398 | _M_construct_p(__y_use_tag, __y_indices, __y)); | |
644b2e4c JW |
399 | } |
400 | ||
401 | template<typename _T1, typename _T2> | |
402 | void | |
403 | construct(pair<_T1, _T2>* __p) | |
404 | { construct(__p, piecewise_construct, tuple<>(), tuple<>()); } | |
405 | ||
ae40b500 | 406 | template<typename _T1, typename _T2, typename _Up, typename _Vp> |
644b2e4c | 407 | void |
ae40b500 | 408 | construct(pair<_T1, _T2>* __p, _Up&& __u, _Vp&& __v) |
644b2e4c JW |
409 | { |
410 | construct(__p, piecewise_construct, | |
ae40b500 JW |
411 | std::forward_as_tuple(std::forward<_Up>(__u)), |
412 | std::forward_as_tuple(std::forward<_Vp>(__v))); | |
644b2e4c JW |
413 | } |
414 | ||
ae40b500 | 415 | template<typename _T1, typename _T2, typename _Up, typename _Vp> |
644b2e4c | 416 | void |
ae40b500 | 417 | construct(pair<_T1, _T2>* __p, const pair<_Up, _Vp>& __x) |
644b2e4c JW |
418 | { |
419 | construct(__p, piecewise_construct, | |
420 | std::forward_as_tuple(__x.first), | |
421 | std::forward_as_tuple(__x.second)); | |
422 | } | |
423 | ||
ae40b500 | 424 | template<typename _T1, typename _T2, typename _Up, typename _Vp> |
644b2e4c | 425 | void |
ae40b500 | 426 | construct(pair<_T1, _T2>* __p, pair<_Up, _Vp>&& __x) |
644b2e4c JW |
427 | { |
428 | construct(__p, piecewise_construct, | |
ae40b500 JW |
429 | std::forward_as_tuple(std::forward<_Up>(__x.first)), |
430 | std::forward_as_tuple(std::forward<_Vp>(__x.second))); | |
644b2e4c | 431 | } |
b1e7c6fc | 432 | #else // make_obj_using_allocator |
ee2f721c JW |
433 | template<typename _Tp, typename... _Args> |
434 | __attribute__((__nonnull__)) | |
435 | void | |
436 | construct(_Tp* __p, _Args&&... __args) | |
437 | { | |
438 | typedef __outermost_alloc_traits<scoped_allocator_adaptor> _O_traits; | |
439 | std::apply([__p, this](auto&&... __newargs) { | |
440 | _O_traits::construct(__outermost(*this), __p, | |
441 | std::forward<decltype(__newargs)>(__newargs)...); | |
442 | }, | |
443 | uses_allocator_construction_args<_Tp>(inner_allocator(), | |
444 | std::forward<_Args>(__args)...)); | |
445 | } | |
b1e7c6fc | 446 | #endif |
677aad9c JW |
447 | |
448 | template<typename _Tp> | |
449 | void destroy(_Tp* __p) | |
450 | { | |
644b2e4c JW |
451 | typedef __outermost_alloc_traits<scoped_allocator_adaptor> _O_traits; |
452 | _O_traits::destroy(__outermost(*this), __p); | |
453 | } | |
677aad9c JW |
454 | |
455 | scoped_allocator_adaptor | |
456 | select_on_container_copy_construction() const | |
457 | { | |
458 | typedef typename _Build_index_tuple<sizeof...(_InnerAllocs)>::__type | |
459 | _Indices; | |
460 | return scoped_allocator_adaptor(_M_tie(), _Indices()); | |
461 | } | |
462 | ||
463 | template <typename _OutA1, typename _OutA2, typename... _InA> | |
464 | friend bool | |
465 | operator==(const scoped_allocator_adaptor<_OutA1, _InA...>& __a, | |
466 | const scoped_allocator_adaptor<_OutA2, _InA...>& __b) noexcept; | |
644b2e4c JW |
467 | |
468 | private: | |
b1e7c6fc | 469 | #if ! __cpp_lib_make_obj_using_allocator |
a4744f62 JW |
470 | template<typename _Ind, typename... _Args> |
471 | tuple<_Args&&...> | |
472 | _M_construct_p(__uses_alloc0, _Ind, tuple<_Args...>& __t) | |
644b2e4c JW |
473 | { return std::move(__t); } |
474 | ||
a4744f62 JW |
475 | template<size_t... _Ind, typename... _Args> |
476 | tuple<allocator_arg_t, inner_allocator_type&, _Args&&...> | |
477 | _M_construct_p(__uses_alloc1_, _Index_tuple<_Ind...>, | |
478 | tuple<_Args...>& __t) | |
644b2e4c | 479 | { |
a4744f62 JW |
480 | return { allocator_arg, inner_allocator(), |
481 | std::get<_Ind>(std::move(__t))... | |
482 | }; | |
644b2e4c JW |
483 | } |
484 | ||
a4744f62 JW |
485 | template<size_t... _Ind, typename... _Args> |
486 | tuple<_Args&&..., inner_allocator_type&> | |
487 | _M_construct_p(__uses_alloc2_, _Index_tuple<_Ind...>, | |
488 | tuple<_Args...>& __t) | |
644b2e4c | 489 | { |
a4744f62 | 490 | return { std::get<_Ind>(std::move(__t))..., inner_allocator() }; |
644b2e4c | 491 | } |
b1e7c6fc | 492 | #endif // ! make_obj_using_allocator |
677aad9c JW |
493 | }; |
494 | ||
c05ab418 | 495 | /// @related std::scoped_allocator_adaptor |
677aad9c JW |
496 | template <typename _OutA1, typename _OutA2, typename... _InA> |
497 | inline bool | |
498 | operator==(const scoped_allocator_adaptor<_OutA1, _InA...>& __a, | |
499 | const scoped_allocator_adaptor<_OutA2, _InA...>& __b) noexcept | |
500 | { | |
501 | return __a.outer_allocator() == __b.outer_allocator() | |
502 | && __a._M_inner == __b._M_inner; | |
503 | } | |
504 | ||
596676d6 | 505 | #if __cpp_impl_three_way_comparison < 201907L |
c05ab418 | 506 | /// @related std::scoped_allocator_adaptor |
677aad9c JW |
507 | template <typename _OutA1, typename _OutA2, typename... _InA> |
508 | inline bool | |
509 | operator!=(const scoped_allocator_adaptor<_OutA1, _InA...>& __a, | |
510 | const scoped_allocator_adaptor<_OutA2, _InA...>& __b) noexcept | |
511 | { return !(__a == __b); } | |
596676d6 | 512 | #endif |
677aad9c JW |
513 | |
514 | /// @} | |
515 | ||
516 | _GLIBCXX_END_NAMESPACE_VERSION | |
517 | } // namespace | |
518 | ||
734f5023 | 519 | #endif // C++11 |
677aad9c JW |
520 | |
521 | #endif // _SCOPED_ALLOCATOR |