blob: 9436dac9c199051972e31be554d69c7bbda04473 [file] [log] [blame]
Howard Hinnante92c3d72010-08-19 18:39:17 +00001// -*- C++ -*-
2//===-------------------------- scoped_allocator --------------------------===//
3//
4// The LLVM Compiler Infrastructure
5//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnante92c3d72010-08-19 18:39:17 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_SCOPED_ALLOCATOR
12#define _LIBCPP_SCOPED_ALLOCATOR
13
14/*
15 scoped_allocator synopsis
16
17namespace std
18{
19
20template <class OuterAlloc, class... InnerAllocs>
21class scoped_allocator_adaptor : public OuterAlloc
22{
23 typedef allocator_traits<OuterAlloc> OuterTraits; // exposition only
Howard Hinnant324bb032010-08-22 00:02:43 +000024 scoped_allocator_adaptor<InnerAllocs...> inner; // exposition only
Howard Hinnante92c3d72010-08-19 18:39:17 +000025public:
26
27 typedef OuterAlloc outer_allocator_type;
28 typedef see below inner_allocator_type;
29
30 typedef typename OuterTraits::value_type value_type;
31 typedef typename OuterTraits::size_type size_type;
32 typedef typename OuterTraits::difference_type difference_type;
33 typedef typename OuterTraits::pointer pointer;
34 typedef typename OuterTraits::const_pointer const_pointer;
35 typedef typename OuterTraits::void_pointer void_pointer;
36 typedef typename OuterTraits::const_void_pointer const_void_pointer;
37
38 typedef see below propagate_on_container_copy_assignment;
39 typedef see below propagate_on_container_move_assignment;
40 typedef see below propagate_on_container_swap;
Marshall Clowf0324bc2015-06-02 16:34:03 +000041 typedef see below is_always_equal;
Howard Hinnante92c3d72010-08-19 18:39:17 +000042
43 template <class Tp>
44 struct rebind
45 {
46 typedef scoped_allocator_adaptor<
47 OuterTraits::template rebind_alloc<Tp>, InnerAllocs...> other;
48 };
49
50 scoped_allocator_adaptor();
51 template <class OuterA2>
52 scoped_allocator_adaptor(OuterA2&& outerAlloc,
Howard Hinnant06674332011-05-28 18:51:12 +000053 const InnerAllocs&... innerAllocs) noexcept;
54 scoped_allocator_adaptor(const scoped_allocator_adaptor& other) noexcept;
55 scoped_allocator_adaptor(scoped_allocator_adaptor&& other) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +000056 template <class OuterA2>
Howard Hinnant06674332011-05-28 18:51:12 +000057 scoped_allocator_adaptor(const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& other) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +000058 template <class OuterA2>
Howard Hinnant06674332011-05-28 18:51:12 +000059 scoped_allocator_adaptor(const scoped_allocator_adaptor<OuterA2, InnerAllocs...>&& other) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +000060
Marshall Clow9533a4a2015-10-25 19:52:47 +000061 scoped_allocator_adaptor& operator=(const scoped_allocator_adaptor&) = default;
62 scoped_allocator_adaptor& operator=(scoped_allocator_adaptor&&) = default;
Howard Hinnante92c3d72010-08-19 18:39:17 +000063 ~scoped_allocator_adaptor();
64
Howard Hinnant06674332011-05-28 18:51:12 +000065 inner_allocator_type& inner_allocator() noexcept;
66 const inner_allocator_type& inner_allocator() const noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +000067
Howard Hinnant06674332011-05-28 18:51:12 +000068 outer_allocator_type& outer_allocator() noexcept;
69 const outer_allocator_type& outer_allocator() const noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +000070
71 pointer allocate(size_type n);
72 pointer allocate(size_type n, const_void_pointer hint);
Howard Hinnant06674332011-05-28 18:51:12 +000073 void deallocate(pointer p, size_type n) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +000074
75 size_type max_size() const;
76 template <class T, class... Args> void construct(T* p, Args&& args);
77 template <class T1, class T2, class... Args1, class... Args2>
78 void construct(pair<T1, T2>* p, piecewise_construct t, tuple<Args1...> x,
79 tuple<Args2...> y);
80 template <class T1, class T2>
81 void construct(pair<T1, T2>* p);
82 template <class T1, class T2, class U, class V>
83 void construct(pair<T1, T2>* p, U&& x, V&& y);
84 template <class T1, class T2, class U, class V>
85 void construct(pair<T1, T2>* p, const pair<U, V>& x);
86 template <class T1, class T2, class U, class V>
87 void construct(pair<T1, T2>* p, pair<U, V>&& x);
88 template <class T> void destroy(T* p);
89
Howard Hinnant06674332011-05-28 18:51:12 +000090 template <class T> void destroy(T* p) noexcept;
91
92 scoped_allocator_adaptor select_on_container_copy_construction() const noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +000093};
94
95template <class OuterA1, class OuterA2, class... InnerAllocs>
96 bool
97 operator==(const scoped_allocator_adaptor<OuterA1, InnerAllocs...>& a,
Howard Hinnant06674332011-05-28 18:51:12 +000098 const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& b) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +000099
100template <class OuterA1, class OuterA2, class... InnerAllocs>
101 bool
102 operator!=(const scoped_allocator_adaptor<OuterA1, InnerAllocs...>& a,
Howard Hinnant06674332011-05-28 18:51:12 +0000103 const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& b) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000104
105} // std
106
107*/
108
109#include <__config>
110#include <memory>
111
Howard Hinnant08e17472011-10-17 20:05:10 +0000112#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnante92c3d72010-08-19 18:39:17 +0000113#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000114#endif
Howard Hinnante92c3d72010-08-19 18:39:17 +0000115
116_LIBCPP_BEGIN_NAMESPACE_STD
117
Howard Hinnant73d21a42010-09-04 23:28:19 +0000118#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_ADVANCED_SFINAE)
Howard Hinnante92c3d72010-08-19 18:39:17 +0000119
120// scoped_allocator_adaptor
121
122template <class ..._Allocs>
123class scoped_allocator_adaptor;
124
125template <class ..._Allocs> struct __get_poc_copy_assignment;
126
127template <class _A0>
128struct __get_poc_copy_assignment<_A0>
129{
130 static const bool value = allocator_traits<_A0>::
131 propagate_on_container_copy_assignment::value;
132};
133
134template <class _A0, class ..._Allocs>
135struct __get_poc_copy_assignment<_A0, _Allocs...>
136{
137 static const bool value =
138 allocator_traits<_A0>::propagate_on_container_copy_assignment::value ||
139 __get_poc_copy_assignment<_Allocs...>::value;
140};
141
142template <class ..._Allocs> struct __get_poc_move_assignment;
143
144template <class _A0>
145struct __get_poc_move_assignment<_A0>
146{
147 static const bool value = allocator_traits<_A0>::
148 propagate_on_container_move_assignment::value;
149};
150
151template <class _A0, class ..._Allocs>
152struct __get_poc_move_assignment<_A0, _Allocs...>
153{
154 static const bool value =
155 allocator_traits<_A0>::propagate_on_container_move_assignment::value ||
156 __get_poc_move_assignment<_Allocs...>::value;
157};
158
159template <class ..._Allocs> struct __get_poc_swap;
160
161template <class _A0>
162struct __get_poc_swap<_A0>
163{
164 static const bool value = allocator_traits<_A0>::
165 propagate_on_container_swap::value;
166};
167
168template <class _A0, class ..._Allocs>
169struct __get_poc_swap<_A0, _Allocs...>
170{
171 static const bool value =
172 allocator_traits<_A0>::propagate_on_container_swap::value ||
173 __get_poc_swap<_Allocs...>::value;
174};
175
Marshall Clowc2a31372015-06-02 21:40:58 +0000176template <class ..._Allocs> struct __get_is_always_equal;
177
178template <class _A0>
179struct __get_is_always_equal<_A0>
180{
181 static const bool value = allocator_traits<_A0>::is_always_equal::value;
182};
183
Marshall Clowf0324bc2015-06-02 16:34:03 +0000184template <class _A0, class ..._Allocs>
Marshall Clowc2a31372015-06-02 21:40:58 +0000185struct __get_is_always_equal<_A0, _Allocs...>
Marshall Clowf0324bc2015-06-02 16:34:03 +0000186{
187 static const bool value =
Marshall Clowbbf87b12015-06-03 16:15:55 +0000188 allocator_traits<_A0>::is_always_equal::value &&
Marshall Clowc2a31372015-06-02 21:40:58 +0000189 __get_is_always_equal<_Allocs...>::value;
Marshall Clowf0324bc2015-06-02 16:34:03 +0000190};
191
Howard Hinnante92c3d72010-08-19 18:39:17 +0000192template <class ..._Allocs>
193class __scoped_allocator_storage;
194
195template <class _OuterAlloc, class... _InnerAllocs>
196class __scoped_allocator_storage<_OuterAlloc, _InnerAllocs...>
197 : public _OuterAlloc
198{
199 typedef _OuterAlloc outer_allocator_type;
200protected:
201 typedef scoped_allocator_adaptor<_InnerAllocs...> inner_allocator_type;
202
203private:
204 inner_allocator_type __inner_;
205
206protected:
Howard Hinnant324bb032010-08-22 00:02:43 +0000207
Howard Hinnant28c97e62010-09-23 16:27:36 +0000208 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant06674332011-05-28 18:51:12 +0000209 __scoped_allocator_storage() _NOEXCEPT {}
Howard Hinnante92c3d72010-08-19 18:39:17 +0000210
211 template <class _OuterA2,
212 class = typename enable_if<
213 is_constructible<outer_allocator_type, _OuterA2>::value
214 >::type>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000215 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante92c3d72010-08-19 18:39:17 +0000216 __scoped_allocator_storage(_OuterA2&& __outerAlloc,
Howard Hinnant06674332011-05-28 18:51:12 +0000217 const _InnerAllocs& ...__innerAllocs) _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +0000218 : outer_allocator_type(_VSTD::forward<_OuterA2>(__outerAlloc)),
Howard Hinnante92c3d72010-08-19 18:39:17 +0000219 __inner_(__innerAllocs...) {}
220
221 template <class _OuterA2,
222 class = typename enable_if<
223 is_constructible<outer_allocator_type, const _OuterA2&>::value
224 >::type>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000225 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante92c3d72010-08-19 18:39:17 +0000226 __scoped_allocator_storage(
Howard Hinnant06674332011-05-28 18:51:12 +0000227 const __scoped_allocator_storage<_OuterA2, _InnerAllocs...>& __other) _NOEXCEPT
Howard Hinnante92c3d72010-08-19 18:39:17 +0000228 : outer_allocator_type(__other.outer_allocator()),
229 __inner_(__other.inner_allocator()) {}
230
231 template <class _OuterA2,
232 class = typename enable_if<
233 is_constructible<outer_allocator_type, _OuterA2>::value
234 >::type>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000235 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante92c3d72010-08-19 18:39:17 +0000236 __scoped_allocator_storage(
Howard Hinnant06674332011-05-28 18:51:12 +0000237 __scoped_allocator_storage<_OuterA2, _InnerAllocs...>&& __other) _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +0000238 : outer_allocator_type(_VSTD::move(__other.outer_allocator())),
239 __inner_(_VSTD::move(__other.inner_allocator())) {}
Howard Hinnante92c3d72010-08-19 18:39:17 +0000240
241 template <class _OuterA2,
242 class = typename enable_if<
243 is_constructible<outer_allocator_type, _OuterA2>::value
244 >::type>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000245 _LIBCPP_INLINE_VISIBILITY
246 __scoped_allocator_storage(_OuterA2&& __o,
Howard Hinnant06674332011-05-28 18:51:12 +0000247 const inner_allocator_type& __i) _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +0000248 : outer_allocator_type(_VSTD::forward<_OuterA2>(__o)),
Howard Hinnant28c97e62010-09-23 16:27:36 +0000249 __inner_(__i)
250 {
251 }
Howard Hinnante92c3d72010-08-19 18:39:17 +0000252
Howard Hinnant28c97e62010-09-23 16:27:36 +0000253 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant06674332011-05-28 18:51:12 +0000254 inner_allocator_type& inner_allocator() _NOEXCEPT {return __inner_;}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000255 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant06674332011-05-28 18:51:12 +0000256 const inner_allocator_type& inner_allocator() const _NOEXCEPT {return __inner_;}
Howard Hinnante92c3d72010-08-19 18:39:17 +0000257
Howard Hinnant28c97e62010-09-23 16:27:36 +0000258 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant06674332011-05-28 18:51:12 +0000259 outer_allocator_type& outer_allocator() _NOEXCEPT
Howard Hinnante92c3d72010-08-19 18:39:17 +0000260 {return static_cast<outer_allocator_type&>(*this);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000261 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant06674332011-05-28 18:51:12 +0000262 const outer_allocator_type& outer_allocator() const _NOEXCEPT
Howard Hinnante92c3d72010-08-19 18:39:17 +0000263 {return static_cast<const outer_allocator_type&>(*this);}
264
265 scoped_allocator_adaptor<outer_allocator_type, _InnerAllocs...>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000266 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant06674332011-05-28 18:51:12 +0000267 select_on_container_copy_construction() const _NOEXCEPT
Howard Hinnante92c3d72010-08-19 18:39:17 +0000268 {
269 return scoped_allocator_adaptor<outer_allocator_type, _InnerAllocs...>
270 (
271 allocator_traits<outer_allocator_type>::
272 select_on_container_copy_construction(outer_allocator()),
273 allocator_traits<inner_allocator_type>::
274 select_on_container_copy_construction(inner_allocator())
275 );
276 }
277
278 template <class...> friend class __scoped_allocator_storage;
279};
280
281template <class _OuterAlloc>
282class __scoped_allocator_storage<_OuterAlloc>
283 : public _OuterAlloc
284{
285 typedef _OuterAlloc outer_allocator_type;
286protected:
287 typedef scoped_allocator_adaptor<_OuterAlloc> inner_allocator_type;
288
Howard Hinnant28c97e62010-09-23 16:27:36 +0000289 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant06674332011-05-28 18:51:12 +0000290 __scoped_allocator_storage() _NOEXCEPT {}
Howard Hinnante92c3d72010-08-19 18:39:17 +0000291
292 template <class _OuterA2,
293 class = typename enable_if<
294 is_constructible<outer_allocator_type, _OuterA2>::value
295 >::type>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000296 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant06674332011-05-28 18:51:12 +0000297 __scoped_allocator_storage(_OuterA2&& __outerAlloc) _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +0000298 : outer_allocator_type(_VSTD::forward<_OuterA2>(__outerAlloc)) {}
Howard Hinnante92c3d72010-08-19 18:39:17 +0000299
300 template <class _OuterA2,
301 class = typename enable_if<
302 is_constructible<outer_allocator_type, const _OuterA2&>::value
303 >::type>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000304 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante92c3d72010-08-19 18:39:17 +0000305 __scoped_allocator_storage(
Howard Hinnant06674332011-05-28 18:51:12 +0000306 const __scoped_allocator_storage<_OuterA2>& __other) _NOEXCEPT
Howard Hinnante92c3d72010-08-19 18:39:17 +0000307 : outer_allocator_type(__other.outer_allocator()) {}
308
309 template <class _OuterA2,
310 class = typename enable_if<
311 is_constructible<outer_allocator_type, _OuterA2>::value
312 >::type>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000313 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante92c3d72010-08-19 18:39:17 +0000314 __scoped_allocator_storage(
Howard Hinnant06674332011-05-28 18:51:12 +0000315 __scoped_allocator_storage<_OuterA2>&& __other) _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +0000316 : outer_allocator_type(_VSTD::move(__other.outer_allocator())) {}
Howard Hinnante92c3d72010-08-19 18:39:17 +0000317
Howard Hinnant28c97e62010-09-23 16:27:36 +0000318 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant06674332011-05-28 18:51:12 +0000319 inner_allocator_type& inner_allocator() _NOEXCEPT
Howard Hinnante92c3d72010-08-19 18:39:17 +0000320 {return static_cast<inner_allocator_type&>(*this);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000321 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant06674332011-05-28 18:51:12 +0000322 const inner_allocator_type& inner_allocator() const _NOEXCEPT
Howard Hinnante92c3d72010-08-19 18:39:17 +0000323 {return static_cast<const inner_allocator_type&>(*this);}
324
Howard Hinnant28c97e62010-09-23 16:27:36 +0000325 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant06674332011-05-28 18:51:12 +0000326 outer_allocator_type& outer_allocator() _NOEXCEPT
Howard Hinnante92c3d72010-08-19 18:39:17 +0000327 {return static_cast<outer_allocator_type&>(*this);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000328 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant06674332011-05-28 18:51:12 +0000329 const outer_allocator_type& outer_allocator() const _NOEXCEPT
Howard Hinnante92c3d72010-08-19 18:39:17 +0000330 {return static_cast<const outer_allocator_type&>(*this);}
331
Howard Hinnant28c97e62010-09-23 16:27:36 +0000332 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante92c3d72010-08-19 18:39:17 +0000333 scoped_allocator_adaptor<outer_allocator_type>
Howard Hinnant06674332011-05-28 18:51:12 +0000334 select_on_container_copy_construction() const _NOEXCEPT
Howard Hinnante92c3d72010-08-19 18:39:17 +0000335 {return scoped_allocator_adaptor<outer_allocator_type>(
336 allocator_traits<outer_allocator_type>::
337 select_on_container_copy_construction(outer_allocator())
338 );}
339
340 __scoped_allocator_storage(const outer_allocator_type& __o,
Howard Hinnant06674332011-05-28 18:51:12 +0000341 const inner_allocator_type& __i) _NOEXCEPT;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000342
343 template <class...> friend class __scoped_allocator_storage;
344};
345
346// __outermost
347
348template <class _Alloc>
349decltype(declval<_Alloc>().outer_allocator(), true_type())
350__has_outer_allocator_test(_Alloc&& __a);
351
352template <class _Alloc>
353false_type
354__has_outer_allocator_test(const volatile _Alloc& __a);
355
356template <class _Alloc>
357struct __has_outer_allocator
358 : public common_type
359 <
360 decltype(__has_outer_allocator_test(declval<_Alloc&>()))
361 >::type
362{
363};
364
365template <class _Alloc, bool = __has_outer_allocator<_Alloc>::value>
366struct __outermost
367{
368 typedef _Alloc type;
Howard Hinnant28c97e62010-09-23 16:27:36 +0000369 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant06674332011-05-28 18:51:12 +0000370 type& operator()(type& __a) const _NOEXCEPT {return __a;}
Howard Hinnante92c3d72010-08-19 18:39:17 +0000371};
372
373template <class _Alloc>
374struct __outermost<_Alloc, true>
375{
376 typedef typename remove_reference
377 <
Howard Hinnant0949eed2011-06-30 21:18:19 +0000378 decltype(_VSTD::declval<_Alloc>().outer_allocator())
Howard Hinnante92c3d72010-08-19 18:39:17 +0000379 >::type _OuterAlloc;
380 typedef typename __outermost<_OuterAlloc>::type type;
Howard Hinnant28c97e62010-09-23 16:27:36 +0000381 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant06674332011-05-28 18:51:12 +0000382 type& operator()(_Alloc& __a) const _NOEXCEPT
Howard Hinnante92c3d72010-08-19 18:39:17 +0000383 {return __outermost<_OuterAlloc>()(__a.outer_allocator());}
384};
385
386template <class _OuterAlloc, class... _InnerAllocs>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000387class _LIBCPP_TYPE_VIS_ONLY scoped_allocator_adaptor<_OuterAlloc, _InnerAllocs...>
Howard Hinnante92c3d72010-08-19 18:39:17 +0000388 : public __scoped_allocator_storage<_OuterAlloc, _InnerAllocs...>
389{
390 typedef __scoped_allocator_storage<_OuterAlloc, _InnerAllocs...> base;
391 typedef allocator_traits<_OuterAlloc> _OuterTraits;
392public:
393 typedef _OuterAlloc outer_allocator_type;
394 typedef typename base::inner_allocator_type inner_allocator_type;
395 typedef typename _OuterTraits::size_type size_type;
396 typedef typename _OuterTraits::difference_type difference_type;
397 typedef typename _OuterTraits::pointer pointer;
398 typedef typename _OuterTraits::const_pointer const_pointer;
399 typedef typename _OuterTraits::void_pointer void_pointer;
400 typedef typename _OuterTraits::const_void_pointer const_void_pointer;
401
402 typedef integral_constant
403 <
404 bool,
405 __get_poc_copy_assignment<outer_allocator_type,
406 _InnerAllocs...>::value
407 > propagate_on_container_copy_assignment;
408 typedef integral_constant
409 <
410 bool,
411 __get_poc_move_assignment<outer_allocator_type,
412 _InnerAllocs...>::value
413 > propagate_on_container_move_assignment;
414 typedef integral_constant
415 <
416 bool,
417 __get_poc_swap<outer_allocator_type, _InnerAllocs...>::value
418 > propagate_on_container_swap;
Marshall Clowf0324bc2015-06-02 16:34:03 +0000419 typedef integral_constant
420 <
421 bool,
Marshall Clowc2a31372015-06-02 21:40:58 +0000422 __get_is_always_equal<outer_allocator_type, _InnerAllocs...>::value
Marshall Clowf0324bc2015-06-02 16:34:03 +0000423 > is_always_equal;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000424
425 template <class _Tp>
426 struct rebind
427 {
428 typedef scoped_allocator_adaptor
429 <
430 typename _OuterTraits::template rebind_alloc<_Tp>, _InnerAllocs...
431 > other;
432 };
433
Howard Hinnant28c97e62010-09-23 16:27:36 +0000434 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant06674332011-05-28 18:51:12 +0000435 scoped_allocator_adaptor() _NOEXCEPT {}
Howard Hinnante92c3d72010-08-19 18:39:17 +0000436 template <class _OuterA2,
437 class = typename enable_if<
438 is_constructible<outer_allocator_type, _OuterA2>::value
439 >::type>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000440 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante92c3d72010-08-19 18:39:17 +0000441 scoped_allocator_adaptor(_OuterA2&& __outerAlloc,
Howard Hinnant06674332011-05-28 18:51:12 +0000442 const _InnerAllocs& ...__innerAllocs) _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +0000443 : base(_VSTD::forward<_OuterA2>(__outerAlloc), __innerAllocs...) {}
Howard Hinnante92c3d72010-08-19 18:39:17 +0000444 // scoped_allocator_adaptor(const scoped_allocator_adaptor& __other) = default;
445 template <class _OuterA2,
446 class = typename enable_if<
447 is_constructible<outer_allocator_type, const _OuterA2&>::value
448 >::type>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000449 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante92c3d72010-08-19 18:39:17 +0000450 scoped_allocator_adaptor(
Howard Hinnant06674332011-05-28 18:51:12 +0000451 const scoped_allocator_adaptor<_OuterA2, _InnerAllocs...>& __other) _NOEXCEPT
Howard Hinnante92c3d72010-08-19 18:39:17 +0000452 : base(__other) {}
453 template <class _OuterA2,
454 class = typename enable_if<
455 is_constructible<outer_allocator_type, _OuterA2>::value
456 >::type>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000457 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante92c3d72010-08-19 18:39:17 +0000458 scoped_allocator_adaptor(
Howard Hinnant06674332011-05-28 18:51:12 +0000459 scoped_allocator_adaptor<_OuterA2, _InnerAllocs...>&& __other) _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +0000460 : base(_VSTD::move(__other)) {}
Howard Hinnante92c3d72010-08-19 18:39:17 +0000461
Marshall Clow9533a4a2015-10-25 19:52:47 +0000462 // scoped_allocator_adaptor& operator=(const scoped_allocator_adaptor&) = default;
463 // scoped_allocator_adaptor& operator=(scoped_allocator_adaptor&&) = default;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000464 // ~scoped_allocator_adaptor() = default;
465
Howard Hinnant28c97e62010-09-23 16:27:36 +0000466 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant06674332011-05-28 18:51:12 +0000467 inner_allocator_type& inner_allocator() _NOEXCEPT
Howard Hinnante92c3d72010-08-19 18:39:17 +0000468 {return base::inner_allocator();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000469 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant06674332011-05-28 18:51:12 +0000470 const inner_allocator_type& inner_allocator() const _NOEXCEPT
Howard Hinnante92c3d72010-08-19 18:39:17 +0000471 {return base::inner_allocator();}
472
Howard Hinnant28c97e62010-09-23 16:27:36 +0000473 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant06674332011-05-28 18:51:12 +0000474 outer_allocator_type& outer_allocator() _NOEXCEPT
Howard Hinnante92c3d72010-08-19 18:39:17 +0000475 {return base::outer_allocator();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000476 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant06674332011-05-28 18:51:12 +0000477 const outer_allocator_type& outer_allocator() const _NOEXCEPT
Howard Hinnante92c3d72010-08-19 18:39:17 +0000478 {return base::outer_allocator();}
479
Howard Hinnant28c97e62010-09-23 16:27:36 +0000480 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante92c3d72010-08-19 18:39:17 +0000481 pointer allocate(size_type __n)
482 {return allocator_traits<outer_allocator_type>::
483 allocate(outer_allocator(), __n);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000484 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante92c3d72010-08-19 18:39:17 +0000485 pointer allocate(size_type __n, const_void_pointer __hint)
486 {return allocator_traits<outer_allocator_type>::
487 allocate(outer_allocator(), __n, __hint);}
488
Howard Hinnant28c97e62010-09-23 16:27:36 +0000489 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant06674332011-05-28 18:51:12 +0000490 void deallocate(pointer __p, size_type __n) _NOEXCEPT
Howard Hinnante92c3d72010-08-19 18:39:17 +0000491 {allocator_traits<outer_allocator_type>::
492 deallocate(outer_allocator(), __p, __n);}
493
Howard Hinnant28c97e62010-09-23 16:27:36 +0000494 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante92c3d72010-08-19 18:39:17 +0000495 size_type max_size() const
Howard Hinnant28c97e62010-09-23 16:27:36 +0000496 {return allocator_traits<outer_allocator_type>::max_size(outer_allocator());}
Howard Hinnante92c3d72010-08-19 18:39:17 +0000497
498 template <class _Tp, class... _Args>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000499 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante92c3d72010-08-19 18:39:17 +0000500 void construct(_Tp* __p, _Args&& ...__args)
501 {__construct(__uses_alloc_ctor<_Tp, inner_allocator_type, _Args...>(),
Howard Hinnant0949eed2011-06-30 21:18:19 +0000502 __p, _VSTD::forward<_Args>(__args)...);}
Howard Hinnante92c3d72010-08-19 18:39:17 +0000503 template <class _Tp>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000504 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante92c3d72010-08-19 18:39:17 +0000505 void destroy(_Tp* __p)
506 {
507 typedef __outermost<outer_allocator_type> _OM;
508 allocator_traits<typename _OM::type>::
509 destroy(_OM()(outer_allocator()), __p);
510 }
511
Howard Hinnant28c97e62010-09-23 16:27:36 +0000512 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant06674332011-05-28 18:51:12 +0000513 scoped_allocator_adaptor select_on_container_copy_construction() const _NOEXCEPT
Howard Hinnante92c3d72010-08-19 18:39:17 +0000514 {return base::select_on_container_copy_construction();}
515
516private:
517
518 template <class _OuterA2,
519 class = typename enable_if<
520 is_constructible<outer_allocator_type, _OuterA2>::value
521 >::type>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000522 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante92c3d72010-08-19 18:39:17 +0000523 scoped_allocator_adaptor(_OuterA2&& __o,
Howard Hinnant06674332011-05-28 18:51:12 +0000524 const inner_allocator_type& __i) _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +0000525 : base(_VSTD::forward<_OuterA2>(__o), __i) {}
Howard Hinnante92c3d72010-08-19 18:39:17 +0000526
527 template <class _Tp, class... _Args>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000528 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante92c3d72010-08-19 18:39:17 +0000529 void __construct(integral_constant<int, 0>, _Tp* __p, _Args&& ...__args)
530 {
531 typedef __outermost<outer_allocator_type> _OM;
532 allocator_traits<typename _OM::type>::construct
533 (
534 _OM()(outer_allocator()),
535 __p,
Howard Hinnant0949eed2011-06-30 21:18:19 +0000536 _VSTD::forward<_Args>(__args)...
Howard Hinnante92c3d72010-08-19 18:39:17 +0000537 );
538 }
539
540 template <class _Tp, class... _Args>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000541 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante92c3d72010-08-19 18:39:17 +0000542 void __construct(integral_constant<int, 1>, _Tp* __p, _Args&& ...__args)
543 {
544 typedef __outermost<outer_allocator_type> _OM;
545 allocator_traits<typename _OM::type>::construct
546 (
547 _OM()(outer_allocator()),
548 __p,
549 allocator_arg,
550 inner_allocator(),
Howard Hinnant0949eed2011-06-30 21:18:19 +0000551 _VSTD::forward<_Args>(__args)...
Howard Hinnante92c3d72010-08-19 18:39:17 +0000552 );
553 }
554
555 template <class _Tp, class... _Args>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000556 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante92c3d72010-08-19 18:39:17 +0000557 void __construct(integral_constant<int, 2>, _Tp* __p, _Args&& ...__args)
558 {
559 typedef __outermost<outer_allocator_type> _OM;
560 allocator_traits<typename _OM::type>::construct
561 (
562 _OM()(outer_allocator()),
563 __p,
Howard Hinnant0949eed2011-06-30 21:18:19 +0000564 _VSTD::forward<_Args>(__args)...,
Howard Hinnante92c3d72010-08-19 18:39:17 +0000565 inner_allocator()
566 );
567 }
568
569 template <class...> friend class __scoped_allocator_storage;
570};
571
572template <class _OuterA1, class _OuterA2>
573inline _LIBCPP_INLINE_VISIBILITY
574bool
575operator==(const scoped_allocator_adaptor<_OuterA1>& __a,
Howard Hinnant06674332011-05-28 18:51:12 +0000576 const scoped_allocator_adaptor<_OuterA2>& __b) _NOEXCEPT
Howard Hinnante92c3d72010-08-19 18:39:17 +0000577{
578 return __a.outer_allocator() == __b.outer_allocator();
579}
580
Howard Hinnantfead2e22011-05-17 20:41:18 +0000581template <class _OuterA1, class _OuterA2, class _InnerA0, class... _InnerAllocs>
Howard Hinnante92c3d72010-08-19 18:39:17 +0000582inline _LIBCPP_INLINE_VISIBILITY
583bool
Howard Hinnantfead2e22011-05-17 20:41:18 +0000584operator==(const scoped_allocator_adaptor<_OuterA1, _InnerA0, _InnerAllocs...>& __a,
Howard Hinnant06674332011-05-28 18:51:12 +0000585 const scoped_allocator_adaptor<_OuterA2, _InnerA0, _InnerAllocs...>& __b) _NOEXCEPT
Howard Hinnante92c3d72010-08-19 18:39:17 +0000586{
587 return __a.outer_allocator() == __b.outer_allocator() &&
588 __a.inner_allocator() == __b.inner_allocator();
589}
590
591template <class _OuterA1, class _OuterA2, class... _InnerAllocs>
592inline _LIBCPP_INLINE_VISIBILITY
593bool
594operator!=(const scoped_allocator_adaptor<_OuterA1, _InnerAllocs...>& __a,
Howard Hinnant06674332011-05-28 18:51:12 +0000595 const scoped_allocator_adaptor<_OuterA2, _InnerAllocs...>& __b) _NOEXCEPT
Howard Hinnante92c3d72010-08-19 18:39:17 +0000596{
597 return !(__a == __b);
598}
599
Howard Hinnant73d21a42010-09-04 23:28:19 +0000600#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_ADVANCED_SFINAE)
Howard Hinnante92c3d72010-08-19 18:39:17 +0000601
602_LIBCPP_END_NAMESPACE_STD
603
604#endif // _LIBCPP_SCOPED_ALLOCATOR