scoped_allocator revision 288943
1227825Stheraven// -*- C++ -*-
2227825Stheraven//===-------------------------- scoped_allocator --------------------------===//
3227825Stheraven//
4227825Stheraven//                     The LLVM Compiler Infrastructure
5227825Stheraven//
6227825Stheraven// This file is dual licensed under the MIT and the University of Illinois Open
7227825Stheraven// Source Licenses. See LICENSE.TXT for details.
8227825Stheraven//
9227825Stheraven//===----------------------------------------------------------------------===//
10227825Stheraven
11227825Stheraven#ifndef _LIBCPP_SCOPED_ALLOCATOR
12227825Stheraven#define _LIBCPP_SCOPED_ALLOCATOR
13227825Stheraven
14227825Stheraven/*
15227825Stheraven    scoped_allocator synopsis
16227825Stheraven
17227825Stheravennamespace std
18227825Stheraven{
19227825Stheraven
20227825Stheraventemplate <class OuterAlloc, class... InnerAllocs>
21227825Stheravenclass scoped_allocator_adaptor : public OuterAlloc
22227825Stheraven{
23227825Stheraven    typedef allocator_traits<OuterAlloc> OuterTraits; // exposition only
24227825Stheraven    scoped_allocator_adaptor<InnerAllocs...> inner;   // exposition only
25227825Stheravenpublic:
26227825Stheraven
27227825Stheraven    typedef OuterAlloc outer_allocator_type;
28227825Stheraven    typedef see below inner_allocator_type;
29227825Stheraven
30227825Stheraven    typedef typename OuterTraits::value_type value_type;
31227825Stheraven    typedef typename OuterTraits::size_type size_type;
32227825Stheraven    typedef typename OuterTraits::difference_type difference_type;
33227825Stheraven    typedef typename OuterTraits::pointer pointer;
34227825Stheraven    typedef typename OuterTraits::const_pointer const_pointer;
35227825Stheraven    typedef typename OuterTraits::void_pointer void_pointer;
36227825Stheraven    typedef typename OuterTraits::const_void_pointer const_void_pointer;
37227825Stheraven
38227825Stheraven    typedef see below propagate_on_container_copy_assignment;
39227825Stheraven    typedef see below propagate_on_container_move_assignment;
40227825Stheraven    typedef see below propagate_on_container_swap;
41288943Sdim    typedef see below is_always_equal;
42227825Stheraven
43227825Stheraven    template <class Tp>
44227825Stheraven        struct rebind
45227825Stheraven        {
46227825Stheraven            typedef scoped_allocator_adaptor<
47227825Stheraven                OuterTraits::template rebind_alloc<Tp>, InnerAllocs...> other;
48227825Stheraven        };
49227825Stheraven
50227825Stheraven    scoped_allocator_adaptor();
51227825Stheraven    template <class OuterA2>
52227825Stheraven        scoped_allocator_adaptor(OuterA2&& outerAlloc,
53227825Stheraven                                 const InnerAllocs&... innerAllocs) noexcept;
54227825Stheraven    scoped_allocator_adaptor(const scoped_allocator_adaptor& other) noexcept;
55227825Stheraven    scoped_allocator_adaptor(scoped_allocator_adaptor&& other) noexcept;
56227825Stheraven    template <class OuterA2>
57227825Stheraven        scoped_allocator_adaptor(const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& other) noexcept;
58227825Stheraven    template <class OuterA2>
59227825Stheraven        scoped_allocator_adaptor(const scoped_allocator_adaptor<OuterA2, InnerAllocs...>&& other) noexcept;
60227825Stheraven
61300770Sdim    ~scoped_allocator_adaptor();
62300770Sdim
63227825Stheraven    inner_allocator_type& inner_allocator() noexcept;
64227825Stheraven    const inner_allocator_type& inner_allocator() const noexcept;
65227825Stheraven
66227825Stheraven    outer_allocator_type& outer_allocator() noexcept;
67227825Stheraven    const outer_allocator_type& outer_allocator() const noexcept;
68227825Stheraven
69227825Stheraven    pointer allocate(size_type n);
70227825Stheraven    pointer allocate(size_type n, const_void_pointer hint);
71227825Stheraven    void deallocate(pointer p, size_type n) noexcept;
72227825Stheraven
73227825Stheraven    size_type max_size() const;
74227825Stheraven    template <class T, class... Args> void construct(T* p, Args&& args);
75227825Stheraven    template <class T1, class T2, class... Args1, class... Args2>
76227825Stheraven        void construct(pair<T1, T2>* p, piecewise_construct t, tuple<Args1...> x,
77227825Stheraven                       tuple<Args2...> y);
78227825Stheraven    template <class T1, class T2>
79227825Stheraven        void construct(pair<T1, T2>* p);
80227825Stheraven    template <class T1, class T2, class U, class V>
81227825Stheraven        void construct(pair<T1, T2>* p, U&& x, V&& y);
82227825Stheraven    template <class T1, class T2, class U, class V>
83227825Stheraven        void construct(pair<T1, T2>* p, const pair<U, V>& x);
84227825Stheraven    template <class T1, class T2, class U, class V>
85227825Stheraven        void construct(pair<T1, T2>* p, pair<U, V>&& x);
86227825Stheraven    template <class T> void destroy(T* p);
87227825Stheraven
88227825Stheraven    template <class T> void destroy(T* p) noexcept;
89227825Stheraven
90227825Stheraven    scoped_allocator_adaptor select_on_container_copy_construction() const noexcept;
91227825Stheraven};
92227825Stheraven
93227825Stheraventemplate <class OuterA1, class OuterA2, class... InnerAllocs>
94227825Stheraven    bool
95227825Stheraven    operator==(const scoped_allocator_adaptor<OuterA1, InnerAllocs...>& a,
96227825Stheraven               const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& b) noexcept;
97227825Stheraven
98227825Stheraventemplate <class OuterA1, class OuterA2, class... InnerAllocs>
99227825Stheraven    bool
100227825Stheraven    operator!=(const scoped_allocator_adaptor<OuterA1, InnerAllocs...>& a,
101227825Stheraven               const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& b) noexcept;
102227825Stheraven
103227825Stheraven}  // std
104227825Stheraven
105227825Stheraven*/
106227825Stheraven
107227825Stheraven#include <__config>
108227825Stheraven#include <memory>
109227825Stheraven
110227825Stheraven#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
111227825Stheraven#pragma GCC system_header
112227825Stheraven#endif
113227825Stheraven
114227825Stheraven_LIBCPP_BEGIN_NAMESPACE_STD
115227825Stheraven
116227825Stheraven#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_ADVANCED_SFINAE)
117227825Stheraven
118227825Stheraven// scoped_allocator_adaptor
119227825Stheraven
120227825Stheraventemplate <class ..._Allocs>
121227825Stheravenclass scoped_allocator_adaptor;
122227825Stheraven
123227825Stheraventemplate <class ..._Allocs> struct __get_poc_copy_assignment;
124227825Stheraven
125227825Stheraventemplate <class _A0>
126227825Stheravenstruct __get_poc_copy_assignment<_A0>
127227825Stheraven{
128227825Stheraven    static const bool value = allocator_traits<_A0>::
129227825Stheraven                              propagate_on_container_copy_assignment::value;
130227825Stheraven};
131227825Stheraven
132227825Stheraventemplate <class _A0, class ..._Allocs>
133227825Stheravenstruct __get_poc_copy_assignment<_A0, _Allocs...>
134227825Stheraven{
135227825Stheraven    static const bool value =
136227825Stheraven        allocator_traits<_A0>::propagate_on_container_copy_assignment::value ||
137227825Stheraven        __get_poc_copy_assignment<_Allocs...>::value;
138227825Stheraven};
139227825Stheraven
140227825Stheraventemplate <class ..._Allocs> struct __get_poc_move_assignment;
141227825Stheraven
142227825Stheraventemplate <class _A0>
143227825Stheravenstruct __get_poc_move_assignment<_A0>
144227825Stheraven{
145227825Stheraven    static const bool value = allocator_traits<_A0>::
146227825Stheraven                              propagate_on_container_move_assignment::value;
147227825Stheraven};
148227825Stheraven
149227825Stheraventemplate <class _A0, class ..._Allocs>
150227825Stheravenstruct __get_poc_move_assignment<_A0, _Allocs...>
151227825Stheraven{
152227825Stheraven    static const bool value =
153227825Stheraven        allocator_traits<_A0>::propagate_on_container_move_assignment::value ||
154227825Stheraven        __get_poc_move_assignment<_Allocs...>::value;
155227825Stheraven};
156227825Stheraven
157227825Stheraventemplate <class ..._Allocs> struct __get_poc_swap;
158227825Stheraven
159227825Stheraventemplate <class _A0>
160227825Stheravenstruct __get_poc_swap<_A0>
161227825Stheraven{
162227825Stheraven    static const bool value = allocator_traits<_A0>::
163227825Stheraven                              propagate_on_container_swap::value;
164227825Stheraven};
165227825Stheraven
166227825Stheraventemplate <class _A0, class ..._Allocs>
167227825Stheravenstruct __get_poc_swap<_A0, _Allocs...>
168227825Stheraven{
169227825Stheraven    static const bool value =
170227825Stheraven        allocator_traits<_A0>::propagate_on_container_swap::value ||
171227825Stheraven        __get_poc_swap<_Allocs...>::value;
172227825Stheraven};
173227825Stheraven
174227825Stheraventemplate <class ..._Allocs> struct __get_is_always_equal;
175227825Stheraven
176288943Sdimtemplate <class _A0>
177288943Sdimstruct __get_is_always_equal<_A0>
178288943Sdim{
179288943Sdim    static const bool value = allocator_traits<_A0>::is_always_equal::value;
180288943Sdim};
181288943Sdim
182288943Sdimtemplate <class _A0, class ..._Allocs>
183288943Sdimstruct __get_is_always_equal<_A0, _Allocs...>
184288943Sdim{
185288943Sdim    static const bool value =
186288943Sdim        allocator_traits<_A0>::is_always_equal::value &&
187288943Sdim        __get_is_always_equal<_Allocs...>::value;
188288943Sdim};
189288943Sdim
190288943Sdimtemplate <class ..._Allocs>
191288943Sdimclass __scoped_allocator_storage;
192227825Stheraven
193227825Stheraventemplate <class _OuterAlloc, class... _InnerAllocs>
194227825Stheravenclass __scoped_allocator_storage<_OuterAlloc, _InnerAllocs...>
195227825Stheraven    : public _OuterAlloc
196227825Stheraven{
197227825Stheraven    typedef _OuterAlloc outer_allocator_type;
198227825Stheravenprotected:
199227825Stheraven    typedef scoped_allocator_adaptor<_InnerAllocs...> inner_allocator_type;
200227825Stheraven
201227825Stheravenprivate:
202227825Stheraven    inner_allocator_type __inner_;
203227825Stheraven
204227825Stheravenprotected:
205227825Stheraven
206227825Stheraven    _LIBCPP_INLINE_VISIBILITY
207227825Stheraven    __scoped_allocator_storage() _NOEXCEPT {}
208227825Stheraven
209227825Stheraven    template <class _OuterA2,
210227825Stheraven              class = typename enable_if<
211227825Stheraven                        is_constructible<outer_allocator_type, _OuterA2>::value
212227825Stheraven                      >::type>
213227825Stheraven        _LIBCPP_INLINE_VISIBILITY
214227825Stheraven        __scoped_allocator_storage(_OuterA2&& __outerAlloc,
215227825Stheraven                                   const _InnerAllocs& ...__innerAllocs) _NOEXCEPT
216227825Stheraven            : outer_allocator_type(_VSTD::forward<_OuterA2>(__outerAlloc)),
217227825Stheraven              __inner_(__innerAllocs...) {}
218227825Stheraven
219227825Stheraven    template <class _OuterA2,
220227825Stheraven              class = typename enable_if<
221227825Stheraven                        is_constructible<outer_allocator_type, const _OuterA2&>::value
222227825Stheraven                      >::type>
223227825Stheraven        _LIBCPP_INLINE_VISIBILITY
224227825Stheraven        __scoped_allocator_storage(
225227825Stheraven            const __scoped_allocator_storage<_OuterA2, _InnerAllocs...>& __other) _NOEXCEPT
226227825Stheraven            : outer_allocator_type(__other.outer_allocator()),
227227825Stheraven              __inner_(__other.inner_allocator()) {}
228227825Stheraven
229227825Stheraven    template <class _OuterA2,
230227825Stheraven              class = typename enable_if<
231227825Stheraven                        is_constructible<outer_allocator_type, _OuterA2>::value
232227825Stheraven                      >::type>
233227825Stheraven        _LIBCPP_INLINE_VISIBILITY
234227825Stheraven        __scoped_allocator_storage(
235227825Stheraven            __scoped_allocator_storage<_OuterA2, _InnerAllocs...>&& __other) _NOEXCEPT
236227825Stheraven            : outer_allocator_type(_VSTD::move(__other.outer_allocator())),
237227825Stheraven              __inner_(_VSTD::move(__other.inner_allocator())) {}
238227825Stheraven
239227825Stheraven    template <class _OuterA2,
240227825Stheraven              class = typename enable_if<
241227825Stheraven                        is_constructible<outer_allocator_type, _OuterA2>::value
242227825Stheraven                      >::type>
243227825Stheraven        _LIBCPP_INLINE_VISIBILITY
244227825Stheraven        __scoped_allocator_storage(_OuterA2&& __o,
245227825Stheraven                                   const inner_allocator_type& __i) _NOEXCEPT
246227825Stheraven            : outer_allocator_type(_VSTD::forward<_OuterA2>(__o)),
247227825Stheraven              __inner_(__i)
248227825Stheraven        {
249227825Stheraven        }
250227825Stheraven
251227825Stheraven    _LIBCPP_INLINE_VISIBILITY
252227825Stheraven    inner_allocator_type& inner_allocator() _NOEXCEPT             {return __inner_;}
253227825Stheraven    _LIBCPP_INLINE_VISIBILITY
254227825Stheraven    const inner_allocator_type& inner_allocator() const _NOEXCEPT {return __inner_;}
255227825Stheraven
256227825Stheraven    _LIBCPP_INLINE_VISIBILITY
257227825Stheraven    outer_allocator_type& outer_allocator() _NOEXCEPT
258227825Stheraven        {return static_cast<outer_allocator_type&>(*this);}
259227825Stheraven    _LIBCPP_INLINE_VISIBILITY
260227825Stheraven    const outer_allocator_type& outer_allocator() const _NOEXCEPT
261227825Stheraven        {return static_cast<const outer_allocator_type&>(*this);}
262227825Stheraven
263227825Stheraven    scoped_allocator_adaptor<outer_allocator_type, _InnerAllocs...>
264227825Stheraven    _LIBCPP_INLINE_VISIBILITY
265227825Stheraven    select_on_container_copy_construction() const _NOEXCEPT
266227825Stheraven        {
267227825Stheraven            return scoped_allocator_adaptor<outer_allocator_type, _InnerAllocs...>
268227825Stheraven            (
269227825Stheraven                allocator_traits<outer_allocator_type>::
270227825Stheraven                    select_on_container_copy_construction(outer_allocator()),
271227825Stheraven                allocator_traits<inner_allocator_type>::
272227825Stheraven                    select_on_container_copy_construction(inner_allocator())
273227825Stheraven            );
274227825Stheraven        }
275227825Stheraven
276227825Stheraven    template <class...> friend class __scoped_allocator_storage;
277227825Stheraven};
278227825Stheraven
279227825Stheraventemplate <class _OuterAlloc>
280227825Stheravenclass __scoped_allocator_storage<_OuterAlloc>
281227825Stheraven    : public _OuterAlloc
282227825Stheraven{
283227825Stheraven    typedef _OuterAlloc outer_allocator_type;
284227825Stheravenprotected:
285227825Stheraven    typedef scoped_allocator_adaptor<_OuterAlloc> inner_allocator_type;
286227825Stheraven
287227825Stheraven    _LIBCPP_INLINE_VISIBILITY
288227825Stheraven    __scoped_allocator_storage() _NOEXCEPT {}
289227825Stheraven
290227825Stheraven    template <class _OuterA2,
291227825Stheraven              class = typename enable_if<
292227825Stheraven                        is_constructible<outer_allocator_type, _OuterA2>::value
293227825Stheraven                      >::type>
294227825Stheraven        _LIBCPP_INLINE_VISIBILITY
295227825Stheraven        __scoped_allocator_storage(_OuterA2&& __outerAlloc) _NOEXCEPT
296227825Stheraven            : outer_allocator_type(_VSTD::forward<_OuterA2>(__outerAlloc)) {}
297227825Stheraven
298227825Stheraven    template <class _OuterA2,
299227825Stheraven              class = typename enable_if<
300227825Stheraven                        is_constructible<outer_allocator_type, const _OuterA2&>::value
301227825Stheraven                      >::type>
302227825Stheraven        _LIBCPP_INLINE_VISIBILITY
303227825Stheraven        __scoped_allocator_storage(
304227825Stheraven            const __scoped_allocator_storage<_OuterA2>& __other) _NOEXCEPT
305227825Stheraven            : outer_allocator_type(__other.outer_allocator()) {}
306227825Stheraven
307227825Stheraven    template <class _OuterA2,
308227825Stheraven              class = typename enable_if<
309227825Stheraven                        is_constructible<outer_allocator_type, _OuterA2>::value
310227825Stheraven                      >::type>
311227825Stheraven        _LIBCPP_INLINE_VISIBILITY
312227825Stheraven        __scoped_allocator_storage(
313227825Stheraven            __scoped_allocator_storage<_OuterA2>&& __other) _NOEXCEPT
314227825Stheraven            : outer_allocator_type(_VSTD::move(__other.outer_allocator())) {}
315227825Stheraven
316227825Stheraven    _LIBCPP_INLINE_VISIBILITY
317227825Stheraven    inner_allocator_type& inner_allocator() _NOEXCEPT
318227825Stheraven        {return static_cast<inner_allocator_type&>(*this);}
319227825Stheraven    _LIBCPP_INLINE_VISIBILITY
320227825Stheraven    const inner_allocator_type& inner_allocator() const _NOEXCEPT
321227825Stheraven        {return static_cast<const inner_allocator_type&>(*this);}
322227825Stheraven
323227825Stheraven    _LIBCPP_INLINE_VISIBILITY
324227825Stheraven    outer_allocator_type& outer_allocator() _NOEXCEPT
325227825Stheraven        {return static_cast<outer_allocator_type&>(*this);}
326227825Stheraven    _LIBCPP_INLINE_VISIBILITY
327227825Stheraven    const outer_allocator_type& outer_allocator() const _NOEXCEPT
328227825Stheraven        {return static_cast<const outer_allocator_type&>(*this);}
329227825Stheraven
330227825Stheraven    _LIBCPP_INLINE_VISIBILITY
331227825Stheraven    scoped_allocator_adaptor<outer_allocator_type>
332227825Stheraven    select_on_container_copy_construction() const _NOEXCEPT
333227825Stheraven        {return scoped_allocator_adaptor<outer_allocator_type>(
334227825Stheraven            allocator_traits<outer_allocator_type>::
335227825Stheraven                select_on_container_copy_construction(outer_allocator())
336227825Stheraven        );}
337227825Stheraven
338227825Stheraven    __scoped_allocator_storage(const outer_allocator_type& __o,
339227825Stheraven                               const inner_allocator_type& __i) _NOEXCEPT;
340227825Stheraven
341227825Stheraven    template <class...> friend class __scoped_allocator_storage;
342227825Stheraven};
343227825Stheraven
344227825Stheraven// __outermost
345227825Stheraven
346227825Stheraventemplate <class _Alloc>
347227825Stheravendecltype(declval<_Alloc>().outer_allocator(), true_type())
348227825Stheraven__has_outer_allocator_test(_Alloc&& __a);
349227825Stheraven
350227825Stheraventemplate <class _Alloc>
351227825Stheravenfalse_type
352227825Stheraven__has_outer_allocator_test(const volatile _Alloc& __a);
353227825Stheraven
354227825Stheraventemplate <class _Alloc>
355227825Stheravenstruct __has_outer_allocator
356227825Stheraven    : public common_type
357227825Stheraven             <
358227825Stheraven                 decltype(__has_outer_allocator_test(declval<_Alloc&>()))
359227825Stheraven             >::type
360227825Stheraven{
361227825Stheraven};
362227825Stheraven
363227825Stheraventemplate <class _Alloc, bool = __has_outer_allocator<_Alloc>::value>
364227825Stheravenstruct __outermost
365227825Stheraven{
366227825Stheraven    typedef _Alloc type;
367227825Stheraven    _LIBCPP_INLINE_VISIBILITY
368227825Stheraven    type& operator()(type& __a) const _NOEXCEPT {return __a;}
369227825Stheraven};
370227825Stheraven
371227825Stheraventemplate <class _Alloc>
372227825Stheravenstruct __outermost<_Alloc, true>
373227825Stheraven{
374227825Stheraven    typedef typename remove_reference
375227825Stheraven                     <
376227825Stheraven                        decltype(_VSTD::declval<_Alloc>().outer_allocator())
377227825Stheraven                     >::type                                    _OuterAlloc;
378227825Stheraven    typedef typename __outermost<_OuterAlloc>::type             type;
379227825Stheraven    _LIBCPP_INLINE_VISIBILITY
380227825Stheraven    type& operator()(_Alloc& __a) const _NOEXCEPT
381227825Stheraven        {return __outermost<_OuterAlloc>()(__a.outer_allocator());}
382227825Stheraven};
383227825Stheraven
384227825Stheraventemplate <class _OuterAlloc, class... _InnerAllocs>
385227825Stheravenclass _LIBCPP_TYPE_VIS_ONLY scoped_allocator_adaptor<_OuterAlloc, _InnerAllocs...>
386227825Stheraven    : public __scoped_allocator_storage<_OuterAlloc, _InnerAllocs...>
387261272Sdim{
388227825Stheraven    typedef __scoped_allocator_storage<_OuterAlloc, _InnerAllocs...> base;
389227825Stheraven    typedef allocator_traits<_OuterAlloc>             _OuterTraits;
390227825Stheravenpublic:
391227825Stheraven    typedef _OuterAlloc                               outer_allocator_type;
392227825Stheraven    typedef typename base::inner_allocator_type       inner_allocator_type;
393227825Stheraven    typedef typename _OuterTraits::size_type          size_type;
394227825Stheraven    typedef typename _OuterTraits::difference_type    difference_type;
395227825Stheraven    typedef typename _OuterTraits::pointer            pointer;
396227825Stheraven    typedef typename _OuterTraits::const_pointer      const_pointer;
397227825Stheraven    typedef typename _OuterTraits::void_pointer       void_pointer;
398227825Stheraven    typedef typename _OuterTraits::const_void_pointer const_void_pointer;
399227825Stheraven
400227825Stheraven    typedef integral_constant
401227825Stheraven            <
402227825Stheraven                bool,
403227825Stheraven                __get_poc_copy_assignment<outer_allocator_type,
404227825Stheraven                                          _InnerAllocs...>::value
405227825Stheraven            > propagate_on_container_copy_assignment;
406227825Stheraven    typedef integral_constant
407227825Stheraven            <
408227825Stheraven                bool,
409227825Stheraven                __get_poc_move_assignment<outer_allocator_type,
410227825Stheraven                                          _InnerAllocs...>::value
411227825Stheraven            > propagate_on_container_move_assignment;
412227825Stheraven    typedef integral_constant
413227825Stheraven            <
414227825Stheraven                bool,
415227825Stheraven                __get_poc_swap<outer_allocator_type, _InnerAllocs...>::value
416227825Stheraven            > propagate_on_container_swap;
417227825Stheraven    typedef integral_constant
418227825Stheraven            <
419288943Sdim                bool,
420288943Sdim                __get_is_always_equal<outer_allocator_type, _InnerAllocs...>::value
421288943Sdim            > is_always_equal;
422288943Sdim
423288943Sdim    template <class _Tp>
424227825Stheraven    struct rebind
425227825Stheraven    {
426227825Stheraven        typedef scoped_allocator_adaptor
427227825Stheraven        <
428227825Stheraven            typename _OuterTraits::template rebind_alloc<_Tp>, _InnerAllocs...
429227825Stheraven        > other;
430227825Stheraven    };
431227825Stheraven
432227825Stheraven    _LIBCPP_INLINE_VISIBILITY
433227825Stheraven    scoped_allocator_adaptor() _NOEXCEPT {}
434227825Stheraven    template <class _OuterA2,
435227825Stheraven              class = typename enable_if<
436227825Stheraven                        is_constructible<outer_allocator_type, _OuterA2>::value
437227825Stheraven                      >::type>
438227825Stheraven        _LIBCPP_INLINE_VISIBILITY
439227825Stheraven        scoped_allocator_adaptor(_OuterA2&& __outerAlloc,
440227825Stheraven                                 const _InnerAllocs& ...__innerAllocs) _NOEXCEPT
441227825Stheraven            : base(_VSTD::forward<_OuterA2>(__outerAlloc), __innerAllocs...) {}
442227825Stheraven    // scoped_allocator_adaptor(const scoped_allocator_adaptor& __other) = default;
443227825Stheraven    template <class _OuterA2,
444227825Stheraven              class = typename enable_if<
445227825Stheraven                        is_constructible<outer_allocator_type, const _OuterA2&>::value
446227825Stheraven                      >::type>
447227825Stheraven        _LIBCPP_INLINE_VISIBILITY
448227825Stheraven        scoped_allocator_adaptor(
449227825Stheraven            const scoped_allocator_adaptor<_OuterA2, _InnerAllocs...>& __other) _NOEXCEPT
450227825Stheraven                : base(__other) {}
451227825Stheraven    template <class _OuterA2,
452227825Stheraven              class = typename enable_if<
453227825Stheraven                        is_constructible<outer_allocator_type, _OuterA2>::value
454227825Stheraven                      >::type>
455227825Stheraven        _LIBCPP_INLINE_VISIBILITY
456227825Stheraven        scoped_allocator_adaptor(
457227825Stheraven            scoped_allocator_adaptor<_OuterA2, _InnerAllocs...>&& __other) _NOEXCEPT
458227825Stheraven                : base(_VSTD::move(__other)) {}
459227825Stheraven
460227825Stheraven    // ~scoped_allocator_adaptor() = default;
461227825Stheraven
462300770Sdim    _LIBCPP_INLINE_VISIBILITY
463300770Sdim    inner_allocator_type& inner_allocator() _NOEXCEPT
464227825Stheraven        {return base::inner_allocator();}
465227825Stheraven    _LIBCPP_INLINE_VISIBILITY
466227825Stheraven    const inner_allocator_type& inner_allocator() const _NOEXCEPT
467227825Stheraven        {return base::inner_allocator();}
468227825Stheraven
469227825Stheraven    _LIBCPP_INLINE_VISIBILITY
470227825Stheraven    outer_allocator_type& outer_allocator() _NOEXCEPT
471227825Stheraven        {return base::outer_allocator();}
472227825Stheraven    _LIBCPP_INLINE_VISIBILITY
473227825Stheraven    const outer_allocator_type& outer_allocator() const _NOEXCEPT
474227825Stheraven        {return base::outer_allocator();}
475227825Stheraven
476227825Stheraven    _LIBCPP_INLINE_VISIBILITY
477227825Stheraven    pointer allocate(size_type __n)
478227825Stheraven        {return allocator_traits<outer_allocator_type>::
479227825Stheraven            allocate(outer_allocator(), __n);}
480227825Stheraven    _LIBCPP_INLINE_VISIBILITY
481227825Stheraven    pointer allocate(size_type __n, const_void_pointer __hint)
482227825Stheraven        {return allocator_traits<outer_allocator_type>::
483227825Stheraven            allocate(outer_allocator(), __n, __hint);}
484227825Stheraven
485227825Stheraven    _LIBCPP_INLINE_VISIBILITY
486227825Stheraven    void deallocate(pointer __p, size_type __n) _NOEXCEPT
487227825Stheraven        {allocator_traits<outer_allocator_type>::
488227825Stheraven            deallocate(outer_allocator(), __p, __n);}
489227825Stheraven
490227825Stheraven    _LIBCPP_INLINE_VISIBILITY
491227825Stheraven    size_type max_size() const
492227825Stheraven        {return allocator_traits<outer_allocator_type>::max_size(outer_allocator());}
493227825Stheraven
494227825Stheraven    template <class _Tp, class... _Args>
495227825Stheraven        _LIBCPP_INLINE_VISIBILITY
496227825Stheraven        void construct(_Tp* __p, _Args&& ...__args)
497227825Stheraven            {__construct(__uses_alloc_ctor<_Tp, inner_allocator_type, _Args...>(),
498227825Stheraven                         __p, _VSTD::forward<_Args>(__args)...);}
499227825Stheraven    template <class _Tp>
500227825Stheraven        _LIBCPP_INLINE_VISIBILITY
501227825Stheraven        void destroy(_Tp* __p)
502227825Stheraven            {
503227825Stheraven                typedef __outermost<outer_allocator_type> _OM;
504227825Stheraven                allocator_traits<typename _OM::type>::
505227825Stheraven                                         destroy(_OM()(outer_allocator()), __p);
506227825Stheraven            }
507227825Stheraven
508227825Stheraven    _LIBCPP_INLINE_VISIBILITY
509227825Stheraven    scoped_allocator_adaptor select_on_container_copy_construction() const _NOEXCEPT
510227825Stheraven        {return base::select_on_container_copy_construction();}
511227825Stheraven
512227825Stheravenprivate:
513227825Stheraven
514227825Stheraven    template <class _OuterA2,
515227825Stheraven              class = typename enable_if<
516227825Stheraven                        is_constructible<outer_allocator_type, _OuterA2>::value
517227825Stheraven                      >::type>
518227825Stheraven    _LIBCPP_INLINE_VISIBILITY
519227825Stheraven    scoped_allocator_adaptor(_OuterA2&& __o,
520227825Stheraven                             const inner_allocator_type& __i) _NOEXCEPT
521227825Stheraven        : base(_VSTD::forward<_OuterA2>(__o), __i) {}
522227825Stheraven
523227825Stheraven    template <class _Tp, class... _Args>
524227825Stheraven        _LIBCPP_INLINE_VISIBILITY
525227825Stheraven        void __construct(integral_constant<int, 0>, _Tp* __p, _Args&& ...__args)
526227825Stheraven            {
527227825Stheraven                typedef __outermost<outer_allocator_type> _OM;
528227825Stheraven                allocator_traits<typename _OM::type>::construct
529227825Stheraven                (
530227825Stheraven                    _OM()(outer_allocator()),
531227825Stheraven                    __p,
532227825Stheraven                    _VSTD::forward<_Args>(__args)...
533227825Stheraven                );
534227825Stheraven            }
535227825Stheraven
536227825Stheraven    template <class _Tp, class... _Args>
537227825Stheraven        _LIBCPP_INLINE_VISIBILITY
538227825Stheraven        void __construct(integral_constant<int, 1>, _Tp* __p, _Args&& ...__args)
539227825Stheraven            {
540227825Stheraven                typedef __outermost<outer_allocator_type> _OM;
541227825Stheraven                allocator_traits<typename _OM::type>::construct
542227825Stheraven                (
543227825Stheraven                    _OM()(outer_allocator()),
544227825Stheraven                    __p,
545227825Stheraven                    allocator_arg,
546227825Stheraven                    inner_allocator(),
547227825Stheraven                    _VSTD::forward<_Args>(__args)...
548227825Stheraven                );
549227825Stheraven            }
550227825Stheraven
551227825Stheraven    template <class _Tp, class... _Args>
552227825Stheraven        _LIBCPP_INLINE_VISIBILITY
553227825Stheraven        void __construct(integral_constant<int, 2>, _Tp* __p, _Args&& ...__args)
554227825Stheraven            {
555227825Stheraven                typedef __outermost<outer_allocator_type> _OM;
556227825Stheraven                allocator_traits<typename _OM::type>::construct
557227825Stheraven                (
558227825Stheraven                    _OM()(outer_allocator()),
559227825Stheraven                    __p,
560227825Stheraven                    _VSTD::forward<_Args>(__args)...,
561227825Stheraven                    inner_allocator()
562227825Stheraven                );
563227825Stheraven            }
564227825Stheraven
565227825Stheraven    template <class...> friend class __scoped_allocator_storage;
566227825Stheraven};
567227825Stheraven
568227825Stheraventemplate <class _OuterA1, class _OuterA2>
569227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
570227825Stheravenbool
571227825Stheravenoperator==(const scoped_allocator_adaptor<_OuterA1>& __a,
572227825Stheraven           const scoped_allocator_adaptor<_OuterA2>& __b) _NOEXCEPT
573227825Stheraven{
574227825Stheraven    return __a.outer_allocator() == __b.outer_allocator();
575227825Stheraven}
576227825Stheraven
577227825Stheraventemplate <class _OuterA1, class _OuterA2, class _InnerA0, class... _InnerAllocs>
578227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
579227825Stheravenbool
580227825Stheravenoperator==(const scoped_allocator_adaptor<_OuterA1, _InnerA0, _InnerAllocs...>& __a,
581227825Stheraven           const scoped_allocator_adaptor<_OuterA2, _InnerA0, _InnerAllocs...>& __b) _NOEXCEPT
582227825Stheraven{
583227825Stheraven    return __a.outer_allocator() == __b.outer_allocator() &&
584227825Stheraven           __a.inner_allocator() == __b.inner_allocator();
585227825Stheraven}
586227825Stheraven
587227825Stheraventemplate <class _OuterA1, class _OuterA2, class... _InnerAllocs>
588227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
589227825Stheravenbool
590227825Stheravenoperator!=(const scoped_allocator_adaptor<_OuterA1, _InnerAllocs...>& __a,
591227825Stheraven           const scoped_allocator_adaptor<_OuterA2, _InnerAllocs...>& __b) _NOEXCEPT
592227825Stheraven{
593227825Stheraven    return !(__a == __b);
594227825Stheraven}
595227825Stheraven
596227825Stheraven#endif  // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_ADVANCED_SFINAE)
597227825Stheraven
598227825Stheraven_LIBCPP_END_NAMESPACE_STD
599227825Stheraven
600227825Stheraven#endif  // _LIBCPP_SCOPED_ALLOCATOR
601227825Stheraven