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