blob: cd4987ad9bb6746dfbb39d935c0b61442250a37b [file] [log] [blame]
Howard Hinnante92c3d72010-08-19 18:39:171// -*- C++ -*-
2//===-------------------------- scoped_allocator --------------------------===//
3//
4// The LLVM Compiler Infrastructure
5//
Howard Hinnantb64f8b02010-11-16 22:09:026// 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:178//
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:4324 scoped_allocator_adaptor<InnerAllocs...> inner; // exposition only
Howard Hinnante92c3d72010-08-19 18:39:1725public:
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:0341 typedef see below is_always_equal;
Howard Hinnante92c3d72010-08-19 18:39:1742
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:1253 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:1756 template <class OuterA2>
Howard Hinnant06674332011-05-28 18:51:1257 scoped_allocator_adaptor(const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& other) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:1758 template <class OuterA2>
Howard Hinnant06674332011-05-28 18:51:1259 scoped_allocator_adaptor(const scoped_allocator_adaptor<OuterA2, InnerAllocs...>&& other) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:1760
61 ~scoped_allocator_adaptor();
62
Howard Hinnant06674332011-05-28 18:51:1263 inner_allocator_type& inner_allocator() noexcept;
64 const inner_allocator_type& inner_allocator() const noexcept;
Howard Hinnante92c3d72010-08-19 18:39:1765
Howard Hinnant06674332011-05-28 18:51:1266 outer_allocator_type& outer_allocator() noexcept;
67 const outer_allocator_type& outer_allocator() const noexcept;
Howard Hinnante92c3d72010-08-19 18:39:1768
69 pointer allocate(size_type n);
70 pointer allocate(size_type n, const_void_pointer hint);
Howard Hinnant06674332011-05-28 18:51:1271 void deallocate(pointer p, size_type n) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:1772
73 size_type max_size() const;
74 template <class T, class... Args> void construct(T* p, Args&& args);
75 template <class T1, class T2, class... Args1, class... Args2>
76 void construct(pair<T1, T2>* p, piecewise_construct t, tuple<Args1...> x,
77 tuple<Args2...> y);
78 template <class T1, class T2>
79 void construct(pair<T1, T2>* p);
80 template <class T1, class T2, class U, class V>
81 void construct(pair<T1, T2>* p, U&& x, V&& y);
82 template <class T1, class T2, class U, class V>
83 void construct(pair<T1, T2>* p, const pair<U, V>& x);
84 template <class T1, class T2, class U, class V>
85 void construct(pair<T1, T2>* p, pair<U, V>&& x);
86 template <class T> void destroy(T* p);
87
Howard Hinnant06674332011-05-28 18:51:1288 template <class T> void destroy(T* p) noexcept;
89
90 scoped_allocator_adaptor select_on_container_copy_construction() const noexcept;
Howard Hinnante92c3d72010-08-19 18:39:1791};
92
93template <class OuterA1, class OuterA2, class... InnerAllocs>
94 bool
95 operator==(const scoped_allocator_adaptor<OuterA1, InnerAllocs...>& a,
Howard Hinnant06674332011-05-28 18:51:1296 const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& b) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:1797
98template <class OuterA1, class OuterA2, class... InnerAllocs>
99 bool
100 operator!=(const scoped_allocator_adaptor<OuterA1, InnerAllocs...>& a,
Howard Hinnant06674332011-05-28 18:51:12101 const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& b) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17102
103} // std
104
105*/
106
107#include <__config>
108#include <memory>
109
Howard Hinnant08e17472011-10-17 20:05:10110#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnante92c3d72010-08-19 18:39:17111#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10112#endif
Howard Hinnante92c3d72010-08-19 18:39:17113
114_LIBCPP_BEGIN_NAMESPACE_STD
115
Howard Hinnant73d21a42010-09-04 23:28:19116#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_ADVANCED_SFINAE)
Howard Hinnante92c3d72010-08-19 18:39:17117
118// scoped_allocator_adaptor
119
120template <class ..._Allocs>
121class scoped_allocator_adaptor;
122
123template <class ..._Allocs> struct __get_poc_copy_assignment;
124
125template <class _A0>
126struct __get_poc_copy_assignment<_A0>
127{
128 static const bool value = allocator_traits<_A0>::
129 propagate_on_container_copy_assignment::value;
130};
131
132template <class _A0, class ..._Allocs>
133struct __get_poc_copy_assignment<_A0, _Allocs...>
134{
135 static const bool value =
136 allocator_traits<_A0>::propagate_on_container_copy_assignment::value ||
137 __get_poc_copy_assignment<_Allocs...>::value;
138};
139
140template <class ..._Allocs> struct __get_poc_move_assignment;
141
142template <class _A0>
143struct __get_poc_move_assignment<_A0>
144{
145 static const bool value = allocator_traits<_A0>::
146 propagate_on_container_move_assignment::value;
147};
148
149template <class _A0, class ..._Allocs>
150struct __get_poc_move_assignment<_A0, _Allocs...>
151{
152 static const bool value =
153 allocator_traits<_A0>::propagate_on_container_move_assignment::value ||
154 __get_poc_move_assignment<_Allocs...>::value;
155};
156
157template <class ..._Allocs> struct __get_poc_swap;
158
159template <class _A0>
160struct __get_poc_swap<_A0>
161{
162 static const bool value = allocator_traits<_A0>::
163 propagate_on_container_swap::value;
164};
165
166template <class _A0, class ..._Allocs>
167struct __get_poc_swap<_A0, _Allocs...>
168{
169 static const bool value =
170 allocator_traits<_A0>::propagate_on_container_swap::value ||
171 __get_poc_swap<_Allocs...>::value;
172};
173
Marshall Clowc2a31372015-06-02 21:40:58174template <class ..._Allocs> struct __get_is_always_equal;
175
176template <class _A0>
177struct __get_is_always_equal<_A0>
178{
179 static const bool value = allocator_traits<_A0>::is_always_equal::value;
180};
181
Marshall Clowf0324bc2015-06-02 16:34:03182template <class _A0, class ..._Allocs>
Marshall Clowc2a31372015-06-02 21:40:58183struct __get_is_always_equal<_A0, _Allocs...>
Marshall Clowf0324bc2015-06-02 16:34:03184{
185 static const bool value =
Marshall Clowbbf87b12015-06-03 16:15:55186 allocator_traits<_A0>::is_always_equal::value &&
Marshall Clowc2a31372015-06-02 21:40:58187 __get_is_always_equal<_Allocs...>::value;
Marshall Clowf0324bc2015-06-02 16:34:03188};
189
Howard Hinnante92c3d72010-08-19 18:39:17190template <class ..._Allocs>
191class __scoped_allocator_storage;
192
193template <class _OuterAlloc, class... _InnerAllocs>
194class __scoped_allocator_storage<_OuterAlloc, _InnerAllocs...>
195 : public _OuterAlloc
196{
197 typedef _OuterAlloc outer_allocator_type;
198protected:
199 typedef scoped_allocator_adaptor<_InnerAllocs...> inner_allocator_type;
200
201private:
202 inner_allocator_type __inner_;
203
204protected:
Howard Hinnant324bb032010-08-22 00:02:43205
Howard Hinnant28c97e62010-09-23 16:27:36206 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant06674332011-05-28 18:51:12207 __scoped_allocator_storage() _NOEXCEPT {}
Howard Hinnante92c3d72010-08-19 18:39:17208
209 template <class _OuterA2,
210 class = typename enable_if<
211 is_constructible<outer_allocator_type, _OuterA2>::value
212 >::type>
Howard Hinnant28c97e62010-09-23 16:27:36213 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante92c3d72010-08-19 18:39:17214 __scoped_allocator_storage(_OuterA2&& __outerAlloc,
Howard Hinnant06674332011-05-28 18:51:12215 const _InnerAllocs& ...__innerAllocs) _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19216 : outer_allocator_type(_VSTD::forward<_OuterA2>(__outerAlloc)),
Howard Hinnante92c3d72010-08-19 18:39:17217 __inner_(__innerAllocs...) {}
218
219 template <class _OuterA2,
220 class = typename enable_if<
221 is_constructible<outer_allocator_type, const _OuterA2&>::value
222 >::type>
Howard Hinnant28c97e62010-09-23 16:27:36223 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante92c3d72010-08-19 18:39:17224 __scoped_allocator_storage(
Howard Hinnant06674332011-05-28 18:51:12225 const __scoped_allocator_storage<_OuterA2, _InnerAllocs...>& __other) _NOEXCEPT
Howard Hinnante92c3d72010-08-19 18:39:17226 : outer_allocator_type(__other.outer_allocator()),
227 __inner_(__other.inner_allocator()) {}
228
229 template <class _OuterA2,
230 class = typename enable_if<
231 is_constructible<outer_allocator_type, _OuterA2>::value
232 >::type>
Howard Hinnant28c97e62010-09-23 16:27:36233 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante92c3d72010-08-19 18:39:17234 __scoped_allocator_storage(
Howard Hinnant06674332011-05-28 18:51:12235 __scoped_allocator_storage<_OuterA2, _InnerAllocs...>&& __other) _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19236 : outer_allocator_type(_VSTD::move(__other.outer_allocator())),
237 __inner_(_VSTD::move(__other.inner_allocator())) {}
Howard Hinnante92c3d72010-08-19 18:39:17238
239 template <class _OuterA2,
240 class = typename enable_if<
241 is_constructible<outer_allocator_type, _OuterA2>::value
242 >::type>
Howard Hinnant28c97e62010-09-23 16:27:36243 _LIBCPP_INLINE_VISIBILITY
244 __scoped_allocator_storage(_OuterA2&& __o,
Howard Hinnant06674332011-05-28 18:51:12245 const inner_allocator_type& __i) _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19246 : outer_allocator_type(_VSTD::forward<_OuterA2>(__o)),
Howard Hinnant28c97e62010-09-23 16:27:36247 __inner_(__i)
248 {
249 }
Howard Hinnante92c3d72010-08-19 18:39:17250
Howard Hinnant28c97e62010-09-23 16:27:36251 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant06674332011-05-28 18:51:12252 inner_allocator_type& inner_allocator() _NOEXCEPT {return __inner_;}
Howard Hinnant28c97e62010-09-23 16:27:36253 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant06674332011-05-28 18:51:12254 const inner_allocator_type& inner_allocator() const _NOEXCEPT {return __inner_;}
Howard Hinnante92c3d72010-08-19 18:39:17255
Howard Hinnant28c97e62010-09-23 16:27:36256 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant06674332011-05-28 18:51:12257 outer_allocator_type& outer_allocator() _NOEXCEPT
Howard Hinnante92c3d72010-08-19 18:39:17258 {return static_cast<outer_allocator_type&>(*this);}
Howard Hinnant28c97e62010-09-23 16:27:36259 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant06674332011-05-28 18:51:12260 const outer_allocator_type& outer_allocator() const _NOEXCEPT
Howard Hinnante92c3d72010-08-19 18:39:17261 {return static_cast<const outer_allocator_type&>(*this);}
262
263 scoped_allocator_adaptor<outer_allocator_type, _InnerAllocs...>
Howard Hinnant28c97e62010-09-23 16:27:36264 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant06674332011-05-28 18:51:12265 select_on_container_copy_construction() const _NOEXCEPT
Howard Hinnante92c3d72010-08-19 18:39:17266 {
267 return scoped_allocator_adaptor<outer_allocator_type, _InnerAllocs...>
268 (
269 allocator_traits<outer_allocator_type>::
270 select_on_container_copy_construction(outer_allocator()),
271 allocator_traits<inner_allocator_type>::
272 select_on_container_copy_construction(inner_allocator())
273 );
274 }
275
276 template <class...> friend class __scoped_allocator_storage;
277};
278
279template <class _OuterAlloc>
280class __scoped_allocator_storage<_OuterAlloc>
281 : public _OuterAlloc
282{
283 typedef _OuterAlloc outer_allocator_type;
284protected:
285 typedef scoped_allocator_adaptor<_OuterAlloc> inner_allocator_type;
286
Howard Hinnant28c97e62010-09-23 16:27:36287 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant06674332011-05-28 18:51:12288 __scoped_allocator_storage() _NOEXCEPT {}
Howard Hinnante92c3d72010-08-19 18:39:17289
290 template <class _OuterA2,
291 class = typename enable_if<
292 is_constructible<outer_allocator_type, _OuterA2>::value
293 >::type>
Howard Hinnant28c97e62010-09-23 16:27:36294 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant06674332011-05-28 18:51:12295 __scoped_allocator_storage(_OuterA2&& __outerAlloc) _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19296 : outer_allocator_type(_VSTD::forward<_OuterA2>(__outerAlloc)) {}
Howard Hinnante92c3d72010-08-19 18:39:17297
298 template <class _OuterA2,
299 class = typename enable_if<
300 is_constructible<outer_allocator_type, const _OuterA2&>::value
301 >::type>
Howard Hinnant28c97e62010-09-23 16:27:36302 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante92c3d72010-08-19 18:39:17303 __scoped_allocator_storage(
Howard Hinnant06674332011-05-28 18:51:12304 const __scoped_allocator_storage<_OuterA2>& __other) _NOEXCEPT
Howard Hinnante92c3d72010-08-19 18:39:17305 : outer_allocator_type(__other.outer_allocator()) {}
306
307 template <class _OuterA2,
308 class = typename enable_if<
309 is_constructible<outer_allocator_type, _OuterA2>::value
310 >::type>
Howard Hinnant28c97e62010-09-23 16:27:36311 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante92c3d72010-08-19 18:39:17312 __scoped_allocator_storage(
Howard Hinnant06674332011-05-28 18:51:12313 __scoped_allocator_storage<_OuterA2>&& __other) _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19314 : outer_allocator_type(_VSTD::move(__other.outer_allocator())) {}
Howard Hinnante92c3d72010-08-19 18:39:17315
Howard Hinnant28c97e62010-09-23 16:27:36316 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant06674332011-05-28 18:51:12317 inner_allocator_type& inner_allocator() _NOEXCEPT
Howard Hinnante92c3d72010-08-19 18:39:17318 {return static_cast<inner_allocator_type&>(*this);}
Howard Hinnant28c97e62010-09-23 16:27:36319 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant06674332011-05-28 18:51:12320 const inner_allocator_type& inner_allocator() const _NOEXCEPT
Howard Hinnante92c3d72010-08-19 18:39:17321 {return static_cast<const inner_allocator_type&>(*this);}
322
Howard Hinnant28c97e62010-09-23 16:27:36323 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant06674332011-05-28 18:51:12324 outer_allocator_type& outer_allocator() _NOEXCEPT
Howard Hinnante92c3d72010-08-19 18:39:17325 {return static_cast<outer_allocator_type&>(*this);}
Howard Hinnant28c97e62010-09-23 16:27:36326 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant06674332011-05-28 18:51:12327 const outer_allocator_type& outer_allocator() const _NOEXCEPT
Howard Hinnante92c3d72010-08-19 18:39:17328 {return static_cast<const outer_allocator_type&>(*this);}
329
Howard Hinnant28c97e62010-09-23 16:27:36330 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante92c3d72010-08-19 18:39:17331 scoped_allocator_adaptor<outer_allocator_type>
Howard Hinnant06674332011-05-28 18:51:12332 select_on_container_copy_construction() const _NOEXCEPT
Howard Hinnante92c3d72010-08-19 18:39:17333 {return scoped_allocator_adaptor<outer_allocator_type>(
334 allocator_traits<outer_allocator_type>::
335 select_on_container_copy_construction(outer_allocator())
336 );}
337
338 __scoped_allocator_storage(const outer_allocator_type& __o,
Howard Hinnant06674332011-05-28 18:51:12339 const inner_allocator_type& __i) _NOEXCEPT;
Howard Hinnante92c3d72010-08-19 18:39:17340
341 template <class...> friend class __scoped_allocator_storage;
342};
343
344// __outermost
345
346template <class _Alloc>
347decltype(declval<_Alloc>().outer_allocator(), true_type())
348__has_outer_allocator_test(_Alloc&& __a);
349
350template <class _Alloc>
351false_type
352__has_outer_allocator_test(const volatile _Alloc& __a);
353
354template <class _Alloc>
355struct __has_outer_allocator
356 : public common_type
357 <
358 decltype(__has_outer_allocator_test(declval<_Alloc&>()))
359 >::type
360{
361};
362
363template <class _Alloc, bool = __has_outer_allocator<_Alloc>::value>
364struct __outermost
365{
366 typedef _Alloc type;
Howard Hinnant28c97e62010-09-23 16:27:36367 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant06674332011-05-28 18:51:12368 type& operator()(type& __a) const _NOEXCEPT {return __a;}
Howard Hinnante92c3d72010-08-19 18:39:17369};
370
371template <class _Alloc>
372struct __outermost<_Alloc, true>
373{
374 typedef typename remove_reference
375 <
Howard Hinnant0949eed2011-06-30 21:18:19376 decltype(_VSTD::declval<_Alloc>().outer_allocator())
Howard Hinnante92c3d72010-08-19 18:39:17377 >::type _OuterAlloc;
378 typedef typename __outermost<_OuterAlloc>::type type;
Howard Hinnant28c97e62010-09-23 16:27:36379 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant06674332011-05-28 18:51:12380 type& operator()(_Alloc& __a) const _NOEXCEPT
Howard Hinnante92c3d72010-08-19 18:39:17381 {return __outermost<_OuterAlloc>()(__a.outer_allocator());}
382};
383
384template <class _OuterAlloc, class... _InnerAllocs>
Howard Hinnant0f678bd2013-08-12 18:38:34385class _LIBCPP_TYPE_VIS_ONLY scoped_allocator_adaptor<_OuterAlloc, _InnerAllocs...>
Howard Hinnante92c3d72010-08-19 18:39:17386 : public __scoped_allocator_storage<_OuterAlloc, _InnerAllocs...>
387{
388 typedef __scoped_allocator_storage<_OuterAlloc, _InnerAllocs...> base;
389 typedef allocator_traits<_OuterAlloc> _OuterTraits;
390public:
391 typedef _OuterAlloc outer_allocator_type;
392 typedef typename base::inner_allocator_type inner_allocator_type;
393 typedef typename _OuterTraits::size_type size_type;
394 typedef typename _OuterTraits::difference_type difference_type;
395 typedef typename _OuterTraits::pointer pointer;
396 typedef typename _OuterTraits::const_pointer const_pointer;
397 typedef typename _OuterTraits::void_pointer void_pointer;
398 typedef typename _OuterTraits::const_void_pointer const_void_pointer;
399
400 typedef integral_constant
401 <
402 bool,
403 __get_poc_copy_assignment<outer_allocator_type,
404 _InnerAllocs...>::value
405 > propagate_on_container_copy_assignment;
406 typedef integral_constant
407 <
408 bool,
409 __get_poc_move_assignment<outer_allocator_type,
410 _InnerAllocs...>::value
411 > propagate_on_container_move_assignment;
412 typedef integral_constant
413 <
414 bool,
415 __get_poc_swap<outer_allocator_type, _InnerAllocs...>::value
416 > propagate_on_container_swap;
Marshall Clowf0324bc2015-06-02 16:34:03417 typedef integral_constant
418 <
419 bool,
Marshall Clowc2a31372015-06-02 21:40:58420 __get_is_always_equal<outer_allocator_type, _InnerAllocs...>::value
Marshall Clowf0324bc2015-06-02 16:34:03421 > is_always_equal;
Howard Hinnante92c3d72010-08-19 18:39:17422
423 template <class _Tp>
424 struct rebind
425 {
426 typedef scoped_allocator_adaptor
427 <
428 typename _OuterTraits::template rebind_alloc<_Tp>, _InnerAllocs...
429 > other;
430 };
431
Howard Hinnant28c97e62010-09-23 16:27:36432 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant06674332011-05-28 18:51:12433 scoped_allocator_adaptor() _NOEXCEPT {}
Howard Hinnante92c3d72010-08-19 18:39:17434 template <class _OuterA2,
435 class = typename enable_if<
436 is_constructible<outer_allocator_type, _OuterA2>::value
437 >::type>
Howard Hinnant28c97e62010-09-23 16:27:36438 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante92c3d72010-08-19 18:39:17439 scoped_allocator_adaptor(_OuterA2&& __outerAlloc,
Howard Hinnant06674332011-05-28 18:51:12440 const _InnerAllocs& ...__innerAllocs) _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19441 : base(_VSTD::forward<_OuterA2>(__outerAlloc), __innerAllocs...) {}
Howard Hinnante92c3d72010-08-19 18:39:17442 // scoped_allocator_adaptor(const scoped_allocator_adaptor& __other) = default;
443 template <class _OuterA2,
444 class = typename enable_if<
445 is_constructible<outer_allocator_type, const _OuterA2&>::value
446 >::type>
Howard Hinnant28c97e62010-09-23 16:27:36447 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante92c3d72010-08-19 18:39:17448 scoped_allocator_adaptor(
Howard Hinnant06674332011-05-28 18:51:12449 const scoped_allocator_adaptor<_OuterA2, _InnerAllocs...>& __other) _NOEXCEPT
Howard Hinnante92c3d72010-08-19 18:39:17450 : base(__other) {}
451 template <class _OuterA2,
452 class = typename enable_if<
453 is_constructible<outer_allocator_type, _OuterA2>::value
454 >::type>
Howard Hinnant28c97e62010-09-23 16:27:36455 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante92c3d72010-08-19 18:39:17456 scoped_allocator_adaptor(
Howard Hinnant06674332011-05-28 18:51:12457 scoped_allocator_adaptor<_OuterA2, _InnerAllocs...>&& __other) _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19458 : base(_VSTD::move(__other)) {}
Howard Hinnante92c3d72010-08-19 18:39:17459
460 // ~scoped_allocator_adaptor() = default;
461
Howard Hinnant28c97e62010-09-23 16:27:36462 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant06674332011-05-28 18:51:12463 inner_allocator_type& inner_allocator() _NOEXCEPT
Howard Hinnante92c3d72010-08-19 18:39:17464 {return base::inner_allocator();}
Howard Hinnant28c97e62010-09-23 16:27:36465 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant06674332011-05-28 18:51:12466 const inner_allocator_type& inner_allocator() const _NOEXCEPT
Howard Hinnante92c3d72010-08-19 18:39:17467 {return base::inner_allocator();}
468
Howard Hinnant28c97e62010-09-23 16:27:36469 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant06674332011-05-28 18:51:12470 outer_allocator_type& outer_allocator() _NOEXCEPT
Howard Hinnante92c3d72010-08-19 18:39:17471 {return base::outer_allocator();}
Howard Hinnant28c97e62010-09-23 16:27:36472 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant06674332011-05-28 18:51:12473 const outer_allocator_type& outer_allocator() const _NOEXCEPT
Howard Hinnante92c3d72010-08-19 18:39:17474 {return base::outer_allocator();}
475
Howard Hinnant28c97e62010-09-23 16:27:36476 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante92c3d72010-08-19 18:39:17477 pointer allocate(size_type __n)
478 {return allocator_traits<outer_allocator_type>::
479 allocate(outer_allocator(), __n);}
Howard Hinnant28c97e62010-09-23 16:27:36480 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante92c3d72010-08-19 18:39:17481 pointer allocate(size_type __n, const_void_pointer __hint)
482 {return allocator_traits<outer_allocator_type>::
483 allocate(outer_allocator(), __n, __hint);}
484
Howard Hinnant28c97e62010-09-23 16:27:36485 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant06674332011-05-28 18:51:12486 void deallocate(pointer __p, size_type __n) _NOEXCEPT
Howard Hinnante92c3d72010-08-19 18:39:17487 {allocator_traits<outer_allocator_type>::
488 deallocate(outer_allocator(), __p, __n);}
489
Howard Hinnant28c97e62010-09-23 16:27:36490 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante92c3d72010-08-19 18:39:17491 size_type max_size() const
Howard Hinnant28c97e62010-09-23 16:27:36492 {return allocator_traits<outer_allocator_type>::max_size(outer_allocator());}
Howard Hinnante92c3d72010-08-19 18:39:17493
494 template <class _Tp, class... _Args>
Howard Hinnant28c97e62010-09-23 16:27:36495 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante92c3d72010-08-19 18:39:17496 void construct(_Tp* __p, _Args&& ...__args)
497 {__construct(__uses_alloc_ctor<_Tp, inner_allocator_type, _Args...>(),
Howard Hinnant0949eed2011-06-30 21:18:19498 __p, _VSTD::forward<_Args>(__args)...);}
Howard Hinnante92c3d72010-08-19 18:39:17499 template <class _Tp>
Howard Hinnant28c97e62010-09-23 16:27:36500 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante92c3d72010-08-19 18:39:17501 void destroy(_Tp* __p)
502 {
503 typedef __outermost<outer_allocator_type> _OM;
504 allocator_traits<typename _OM::type>::
505 destroy(_OM()(outer_allocator()), __p);
506 }
507
Howard Hinnant28c97e62010-09-23 16:27:36508 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant06674332011-05-28 18:51:12509 scoped_allocator_adaptor select_on_container_copy_construction() const _NOEXCEPT
Howard Hinnante92c3d72010-08-19 18:39:17510 {return base::select_on_container_copy_construction();}
511
512private:
513
514 template <class _OuterA2,
515 class = typename enable_if<
516 is_constructible<outer_allocator_type, _OuterA2>::value
517 >::type>
Howard Hinnant28c97e62010-09-23 16:27:36518 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante92c3d72010-08-19 18:39:17519 scoped_allocator_adaptor(_OuterA2&& __o,
Howard Hinnant06674332011-05-28 18:51:12520 const inner_allocator_type& __i) _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19521 : base(_VSTD::forward<_OuterA2>(__o), __i) {}
Howard Hinnante92c3d72010-08-19 18:39:17522
523 template <class _Tp, class... _Args>
Howard Hinnant28c97e62010-09-23 16:27:36524 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante92c3d72010-08-19 18:39:17525 void __construct(integral_constant<int, 0>, _Tp* __p, _Args&& ...__args)
526 {
527 typedef __outermost<outer_allocator_type> _OM;
528 allocator_traits<typename _OM::type>::construct
529 (
530 _OM()(outer_allocator()),
531 __p,
Howard Hinnant0949eed2011-06-30 21:18:19532 _VSTD::forward<_Args>(__args)...
Howard Hinnante92c3d72010-08-19 18:39:17533 );
534 }
535
536 template <class _Tp, class... _Args>
Howard Hinnant28c97e62010-09-23 16:27:36537 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante92c3d72010-08-19 18:39:17538 void __construct(integral_constant<int, 1>, _Tp* __p, _Args&& ...__args)
539 {
540 typedef __outermost<outer_allocator_type> _OM;
541 allocator_traits<typename _OM::type>::construct
542 (
543 _OM()(outer_allocator()),
544 __p,
545 allocator_arg,
546 inner_allocator(),
Howard Hinnant0949eed2011-06-30 21:18:19547 _VSTD::forward<_Args>(__args)...
Howard Hinnante92c3d72010-08-19 18:39:17548 );
549 }
550
551 template <class _Tp, class... _Args>
Howard Hinnant28c97e62010-09-23 16:27:36552 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante92c3d72010-08-19 18:39:17553 void __construct(integral_constant<int, 2>, _Tp* __p, _Args&& ...__args)
554 {
555 typedef __outermost<outer_allocator_type> _OM;
556 allocator_traits<typename _OM::type>::construct
557 (
558 _OM()(outer_allocator()),
559 __p,
Howard Hinnant0949eed2011-06-30 21:18:19560 _VSTD::forward<_Args>(__args)...,
Howard Hinnante92c3d72010-08-19 18:39:17561 inner_allocator()
562 );
563 }
564
565 template <class...> friend class __scoped_allocator_storage;
566};
567
568template <class _OuterA1, class _OuterA2>
569inline _LIBCPP_INLINE_VISIBILITY
570bool
571operator==(const scoped_allocator_adaptor<_OuterA1>& __a,
Howard Hinnant06674332011-05-28 18:51:12572 const scoped_allocator_adaptor<_OuterA2>& __b) _NOEXCEPT
Howard Hinnante92c3d72010-08-19 18:39:17573{
574 return __a.outer_allocator() == __b.outer_allocator();
575}
576
Howard Hinnantfead2e22011-05-17 20:41:18577template <class _OuterA1, class _OuterA2, class _InnerA0, class... _InnerAllocs>
Howard Hinnante92c3d72010-08-19 18:39:17578inline _LIBCPP_INLINE_VISIBILITY
579bool
Howard Hinnantfead2e22011-05-17 20:41:18580operator==(const scoped_allocator_adaptor<_OuterA1, _InnerA0, _InnerAllocs...>& __a,
Howard Hinnant06674332011-05-28 18:51:12581 const scoped_allocator_adaptor<_OuterA2, _InnerA0, _InnerAllocs...>& __b) _NOEXCEPT
Howard Hinnante92c3d72010-08-19 18:39:17582{
583 return __a.outer_allocator() == __b.outer_allocator() &&
584 __a.inner_allocator() == __b.inner_allocator();
585}
586
587template <class _OuterA1, class _OuterA2, class... _InnerAllocs>
588inline _LIBCPP_INLINE_VISIBILITY
589bool
590operator!=(const scoped_allocator_adaptor<_OuterA1, _InnerAllocs...>& __a,
Howard Hinnant06674332011-05-28 18:51:12591 const scoped_allocator_adaptor<_OuterA2, _InnerAllocs...>& __b) _NOEXCEPT
Howard Hinnante92c3d72010-08-19 18:39:17592{
593 return !(__a == __b);
594}
595
Howard Hinnant73d21a42010-09-04 23:28:19596#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_ADVANCED_SFINAE)
Howard Hinnante92c3d72010-08-19 18:39:17597
598_LIBCPP_END_NAMESPACE_STD
599
600#endif // _LIBCPP_SCOPED_ALLOCATOR