120cc2a42SHoward Hinnant// -*- C++ -*- 220cc2a42SHoward Hinnant//===-------------------------- scoped_allocator --------------------------===// 320cc2a42SHoward Hinnant// 420cc2a42SHoward Hinnant// The LLVM Compiler Infrastructure 520cc2a42SHoward Hinnant// 620cc2a42SHoward Hinnant// This file is distributed under the University of Illinois Open Source 720cc2a42SHoward Hinnant// License. See LICENSE.TXT for details. 820cc2a42SHoward Hinnant// 920cc2a42SHoward Hinnant//===----------------------------------------------------------------------===// 1020cc2a42SHoward Hinnant 1120cc2a42SHoward Hinnant#ifndef _LIBCPP_SCOPED_ALLOCATOR 1220cc2a42SHoward Hinnant#define _LIBCPP_SCOPED_ALLOCATOR 1320cc2a42SHoward Hinnant 1420cc2a42SHoward Hinnant/* 1520cc2a42SHoward Hinnant scoped_allocator synopsis 1620cc2a42SHoward Hinnant 1720cc2a42SHoward Hinnantnamespace std 1820cc2a42SHoward Hinnant{ 1920cc2a42SHoward Hinnant 2020cc2a42SHoward Hinnanttemplate <class OuterAlloc, class... InnerAllocs> 2120cc2a42SHoward Hinnantclass scoped_allocator_adaptor : public OuterAlloc 2220cc2a42SHoward Hinnant{ 2320cc2a42SHoward Hinnant typedef allocator_traits<OuterAlloc> OuterTraits; // exposition only 2420cc2a42SHoward Hinnant scoped_allocator_adaptor<InnerAllocs...> inner; // exposition only 2520cc2a42SHoward Hinnantpublic: 2620cc2a42SHoward Hinnant 2720cc2a42SHoward Hinnant typedef OuterAlloc outer_allocator_type; 2820cc2a42SHoward Hinnant typedef see below inner_allocator_type; 2920cc2a42SHoward Hinnant 3020cc2a42SHoward Hinnant typedef typename OuterTraits::value_type value_type; 3120cc2a42SHoward Hinnant typedef typename OuterTraits::size_type size_type; 3220cc2a42SHoward Hinnant typedef typename OuterTraits::difference_type difference_type; 3320cc2a42SHoward Hinnant typedef typename OuterTraits::pointer pointer; 3420cc2a42SHoward Hinnant typedef typename OuterTraits::const_pointer const_pointer; 3520cc2a42SHoward Hinnant typedef typename OuterTraits::void_pointer void_pointer; 3620cc2a42SHoward Hinnant typedef typename OuterTraits::const_void_pointer const_void_pointer; 3720cc2a42SHoward Hinnant 3820cc2a42SHoward Hinnant typedef see below propagate_on_container_copy_assignment; 3920cc2a42SHoward Hinnant typedef see below propagate_on_container_move_assignment; 4020cc2a42SHoward Hinnant typedef see below propagate_on_container_swap; 4120cc2a42SHoward Hinnant 4220cc2a42SHoward Hinnant template <class Tp> 4320cc2a42SHoward Hinnant struct rebind 4420cc2a42SHoward Hinnant { 4520cc2a42SHoward Hinnant typedef scoped_allocator_adaptor< 4620cc2a42SHoward Hinnant OuterTraits::template rebind_alloc<Tp>, InnerAllocs...> other; 4720cc2a42SHoward Hinnant }; 4820cc2a42SHoward Hinnant 4920cc2a42SHoward Hinnant scoped_allocator_adaptor(); 5020cc2a42SHoward Hinnant template <class OuterA2> 5120cc2a42SHoward Hinnant scoped_allocator_adaptor(OuterA2&& outerAlloc, 5220cc2a42SHoward Hinnant const InnerAllocs&... innerAllocs); 5320cc2a42SHoward Hinnant scoped_allocator_adaptor(const scoped_allocator_adaptor& other); 5420cc2a42SHoward Hinnant template <class OuterA2> 5520cc2a42SHoward Hinnant scoped_allocator_adaptor(const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& other); 5620cc2a42SHoward Hinnant template <class OuterA2> 5720cc2a42SHoward Hinnant scoped_allocator_adaptor(const scoped_allocator_adaptor<OuterA2, InnerAllocs...>&& other); 5820cc2a42SHoward Hinnant 5920cc2a42SHoward Hinnant ~scoped_allocator_adaptor(); 6020cc2a42SHoward Hinnant 6120cc2a42SHoward Hinnant inner_allocator_type& inner_allocator(); 6220cc2a42SHoward Hinnant const inner_allocator_type& inner_allocator() const; 6320cc2a42SHoward Hinnant 6420cc2a42SHoward Hinnant outer_allocator_type& outer_allocator(); 6520cc2a42SHoward Hinnant const outer_allocator_type& outer_allocator() const; 6620cc2a42SHoward Hinnant 6720cc2a42SHoward Hinnant pointer allocate(size_type n); 6820cc2a42SHoward Hinnant pointer allocate(size_type n, const_void_pointer hint); 6920cc2a42SHoward Hinnant void deallocate(pointer p, size_type n); 7020cc2a42SHoward Hinnant 7120cc2a42SHoward Hinnant size_type max_size() const; 7220cc2a42SHoward Hinnant template <class T, class... Args> void construct(T* p, Args&& args); 7320cc2a42SHoward Hinnant template <class T1, class T2, class... Args1, class... Args2> 7420cc2a42SHoward Hinnant void construct(pair<T1, T2>* p, piecewise_construct t, tuple<Args1...> x, 7520cc2a42SHoward Hinnant tuple<Args2...> y); 7620cc2a42SHoward Hinnant template <class T1, class T2> 7720cc2a42SHoward Hinnant void construct(pair<T1, T2>* p); 7820cc2a42SHoward Hinnant template <class T1, class T2, class U, class V> 7920cc2a42SHoward Hinnant void construct(pair<T1, T2>* p, U&& x, V&& y); 8020cc2a42SHoward Hinnant template <class T1, class T2, class U, class V> 8120cc2a42SHoward Hinnant void construct(pair<T1, T2>* p, const pair<U, V>& x); 8220cc2a42SHoward Hinnant template <class T1, class T2, class U, class V> 8320cc2a42SHoward Hinnant void construct(pair<T1, T2>* p, pair<U, V>&& x); 8420cc2a42SHoward Hinnant template <class T> void destroy(T* p); 8520cc2a42SHoward Hinnant 8620cc2a42SHoward Hinnant scoped_allocator_adaptor select_on_container_copy_construction() const; 8720cc2a42SHoward Hinnant}; 8820cc2a42SHoward Hinnant 8920cc2a42SHoward Hinnanttemplate <class OuterA1, class OuterA2, class... InnerAllocs> 9020cc2a42SHoward Hinnant bool 9120cc2a42SHoward Hinnant operator==(const scoped_allocator_adaptor<OuterA1, InnerAllocs...>& a, 9220cc2a42SHoward Hinnant const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& b); 9320cc2a42SHoward Hinnant 9420cc2a42SHoward Hinnanttemplate <class OuterA1, class OuterA2, class... InnerAllocs> 9520cc2a42SHoward Hinnant bool 9620cc2a42SHoward Hinnant operator!=(const scoped_allocator_adaptor<OuterA1, InnerAllocs...>& a, 9720cc2a42SHoward Hinnant const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& b); 9820cc2a42SHoward Hinnant 9920cc2a42SHoward Hinnant} // std 10020cc2a42SHoward Hinnant 10120cc2a42SHoward Hinnant*/ 10220cc2a42SHoward Hinnant 10320cc2a42SHoward Hinnant#include <__config> 10420cc2a42SHoward Hinnant#include <memory> 10520cc2a42SHoward Hinnant 10620cc2a42SHoward Hinnant#pragma GCC system_header 10720cc2a42SHoward Hinnant 10820cc2a42SHoward Hinnant_LIBCPP_BEGIN_NAMESPACE_STD 10920cc2a42SHoward Hinnant 1107609c9b6SHoward Hinnant#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_ADVANCED_SFINAE) 11120cc2a42SHoward Hinnant 11220cc2a42SHoward Hinnant// scoped_allocator_adaptor 11320cc2a42SHoward Hinnant 11420cc2a42SHoward Hinnanttemplate <class ..._Allocs> 11520cc2a42SHoward Hinnantclass scoped_allocator_adaptor; 11620cc2a42SHoward Hinnant 11720cc2a42SHoward Hinnanttemplate <class ..._Allocs> struct __get_poc_copy_assignment; 11820cc2a42SHoward Hinnant 11920cc2a42SHoward Hinnanttemplate <class _A0> 12020cc2a42SHoward Hinnantstruct __get_poc_copy_assignment<_A0> 12120cc2a42SHoward Hinnant{ 12220cc2a42SHoward Hinnant static const bool value = allocator_traits<_A0>:: 12320cc2a42SHoward Hinnant propagate_on_container_copy_assignment::value; 12420cc2a42SHoward Hinnant}; 12520cc2a42SHoward Hinnant 12620cc2a42SHoward Hinnanttemplate <class _A0, class ..._Allocs> 12720cc2a42SHoward Hinnantstruct __get_poc_copy_assignment<_A0, _Allocs...> 12820cc2a42SHoward Hinnant{ 12920cc2a42SHoward Hinnant static const bool value = 13020cc2a42SHoward Hinnant allocator_traits<_A0>::propagate_on_container_copy_assignment::value || 13120cc2a42SHoward Hinnant __get_poc_copy_assignment<_Allocs...>::value; 13220cc2a42SHoward Hinnant}; 13320cc2a42SHoward Hinnant 13420cc2a42SHoward Hinnanttemplate <class ..._Allocs> struct __get_poc_move_assignment; 13520cc2a42SHoward Hinnant 13620cc2a42SHoward Hinnanttemplate <class _A0> 13720cc2a42SHoward Hinnantstruct __get_poc_move_assignment<_A0> 13820cc2a42SHoward Hinnant{ 13920cc2a42SHoward Hinnant static const bool value = allocator_traits<_A0>:: 14020cc2a42SHoward Hinnant propagate_on_container_move_assignment::value; 14120cc2a42SHoward Hinnant}; 14220cc2a42SHoward Hinnant 14320cc2a42SHoward Hinnanttemplate <class _A0, class ..._Allocs> 14420cc2a42SHoward Hinnantstruct __get_poc_move_assignment<_A0, _Allocs...> 14520cc2a42SHoward Hinnant{ 14620cc2a42SHoward Hinnant static const bool value = 14720cc2a42SHoward Hinnant allocator_traits<_A0>::propagate_on_container_move_assignment::value || 14820cc2a42SHoward Hinnant __get_poc_move_assignment<_Allocs...>::value; 14920cc2a42SHoward Hinnant}; 15020cc2a42SHoward Hinnant 15120cc2a42SHoward Hinnanttemplate <class ..._Allocs> struct __get_poc_swap; 15220cc2a42SHoward Hinnant 15320cc2a42SHoward Hinnanttemplate <class _A0> 15420cc2a42SHoward Hinnantstruct __get_poc_swap<_A0> 15520cc2a42SHoward Hinnant{ 15620cc2a42SHoward Hinnant static const bool value = allocator_traits<_A0>:: 15720cc2a42SHoward Hinnant propagate_on_container_swap::value; 15820cc2a42SHoward Hinnant}; 15920cc2a42SHoward Hinnant 16020cc2a42SHoward Hinnanttemplate <class _A0, class ..._Allocs> 16120cc2a42SHoward Hinnantstruct __get_poc_swap<_A0, _Allocs...> 16220cc2a42SHoward Hinnant{ 16320cc2a42SHoward Hinnant static const bool value = 16420cc2a42SHoward Hinnant allocator_traits<_A0>::propagate_on_container_swap::value || 16520cc2a42SHoward Hinnant __get_poc_swap<_Allocs...>::value; 16620cc2a42SHoward Hinnant}; 16720cc2a42SHoward Hinnant 16820cc2a42SHoward Hinnanttemplate <class ..._Allocs> 16920cc2a42SHoward Hinnantclass __scoped_allocator_storage; 17020cc2a42SHoward Hinnant 17120cc2a42SHoward Hinnanttemplate <class _OuterAlloc, class... _InnerAllocs> 17220cc2a42SHoward Hinnantclass __scoped_allocator_storage<_OuterAlloc, _InnerAllocs...> 17320cc2a42SHoward Hinnant : public _OuterAlloc 17420cc2a42SHoward Hinnant{ 17520cc2a42SHoward Hinnant typedef _OuterAlloc outer_allocator_type; 17620cc2a42SHoward Hinnantprotected: 17720cc2a42SHoward Hinnant typedef scoped_allocator_adaptor<_InnerAllocs...> inner_allocator_type; 17820cc2a42SHoward Hinnant 17920cc2a42SHoward Hinnantprivate: 18020cc2a42SHoward Hinnant inner_allocator_type __inner_; 18120cc2a42SHoward Hinnant 18220cc2a42SHoward Hinnantprotected: 18320cc2a42SHoward Hinnant 184*53ec0b4eSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 18520cc2a42SHoward Hinnant __scoped_allocator_storage() {} 18620cc2a42SHoward Hinnant 18720cc2a42SHoward Hinnant template <class _OuterA2, 18820cc2a42SHoward Hinnant class = typename enable_if< 18920cc2a42SHoward Hinnant is_constructible<outer_allocator_type, _OuterA2>::value 19020cc2a42SHoward Hinnant >::type> 191*53ec0b4eSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 19220cc2a42SHoward Hinnant __scoped_allocator_storage(_OuterA2&& __outerAlloc, 19320cc2a42SHoward Hinnant const _InnerAllocs& ...__innerAllocs) 19420cc2a42SHoward Hinnant : outer_allocator_type(_STD::forward<_OuterA2>(__outerAlloc)), 19520cc2a42SHoward Hinnant __inner_(__innerAllocs...) {} 19620cc2a42SHoward Hinnant 19720cc2a42SHoward Hinnant template <class _OuterA2, 19820cc2a42SHoward Hinnant class = typename enable_if< 19920cc2a42SHoward Hinnant is_constructible<outer_allocator_type, const _OuterA2&>::value 20020cc2a42SHoward Hinnant >::type> 201*53ec0b4eSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 20220cc2a42SHoward Hinnant __scoped_allocator_storage( 20320cc2a42SHoward Hinnant const __scoped_allocator_storage<_OuterA2, _InnerAllocs...>& __other) 20420cc2a42SHoward Hinnant : outer_allocator_type(__other.outer_allocator()), 20520cc2a42SHoward Hinnant __inner_(__other.inner_allocator()) {} 20620cc2a42SHoward Hinnant 20720cc2a42SHoward Hinnant template <class _OuterA2, 20820cc2a42SHoward Hinnant class = typename enable_if< 20920cc2a42SHoward Hinnant is_constructible<outer_allocator_type, _OuterA2>::value 21020cc2a42SHoward Hinnant >::type> 211*53ec0b4eSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 21220cc2a42SHoward Hinnant __scoped_allocator_storage( 21320cc2a42SHoward Hinnant __scoped_allocator_storage<_OuterA2, _InnerAllocs...>&& __other) 21420cc2a42SHoward Hinnant : outer_allocator_type(_STD::move(__other.outer_allocator())), 21520cc2a42SHoward Hinnant __inner_(_STD::move(__other.inner_allocator())) {} 21620cc2a42SHoward Hinnant 21720cc2a42SHoward Hinnant template <class _OuterA2, 21820cc2a42SHoward Hinnant class = typename enable_if< 21920cc2a42SHoward Hinnant is_constructible<outer_allocator_type, _OuterA2>::value 22020cc2a42SHoward Hinnant >::type> 221*53ec0b4eSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 22220cc2a42SHoward Hinnant __scoped_allocator_storage(_OuterA2&& __o, 22320cc2a42SHoward Hinnant const inner_allocator_type& __i) 22420cc2a42SHoward Hinnant : outer_allocator_type(_STD::forward<_OuterA2>(__o)), 22520cc2a42SHoward Hinnant __inner_(__i) 22620cc2a42SHoward Hinnant { 22720cc2a42SHoward Hinnant } 22820cc2a42SHoward Hinnant 229*53ec0b4eSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 23020cc2a42SHoward Hinnant inner_allocator_type& inner_allocator() {return __inner_;} 231*53ec0b4eSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 23220cc2a42SHoward Hinnant const inner_allocator_type& inner_allocator() const {return __inner_;} 23320cc2a42SHoward Hinnant 234*53ec0b4eSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 23520cc2a42SHoward Hinnant outer_allocator_type& outer_allocator() 23620cc2a42SHoward Hinnant {return static_cast<outer_allocator_type&>(*this);} 237*53ec0b4eSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 23820cc2a42SHoward Hinnant const outer_allocator_type& outer_allocator() const 23920cc2a42SHoward Hinnant {return static_cast<const outer_allocator_type&>(*this);} 24020cc2a42SHoward Hinnant 24120cc2a42SHoward Hinnant scoped_allocator_adaptor<outer_allocator_type, _InnerAllocs...> 242*53ec0b4eSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 24320cc2a42SHoward Hinnant select_on_container_copy_construction() const 24420cc2a42SHoward Hinnant { 24520cc2a42SHoward Hinnant return scoped_allocator_adaptor<outer_allocator_type, _InnerAllocs...> 24620cc2a42SHoward Hinnant ( 24720cc2a42SHoward Hinnant allocator_traits<outer_allocator_type>:: 24820cc2a42SHoward Hinnant select_on_container_copy_construction(outer_allocator()), 24920cc2a42SHoward Hinnant allocator_traits<inner_allocator_type>:: 25020cc2a42SHoward Hinnant select_on_container_copy_construction(inner_allocator()) 25120cc2a42SHoward Hinnant ); 25220cc2a42SHoward Hinnant } 25320cc2a42SHoward Hinnant 25420cc2a42SHoward Hinnant template <class...> friend class __scoped_allocator_storage; 25520cc2a42SHoward Hinnant}; 25620cc2a42SHoward Hinnant 25720cc2a42SHoward Hinnanttemplate <class _OuterAlloc> 25820cc2a42SHoward Hinnantclass __scoped_allocator_storage<_OuterAlloc> 25920cc2a42SHoward Hinnant : public _OuterAlloc 26020cc2a42SHoward Hinnant{ 26120cc2a42SHoward Hinnant typedef _OuterAlloc outer_allocator_type; 26220cc2a42SHoward Hinnantprotected: 26320cc2a42SHoward Hinnant typedef scoped_allocator_adaptor<_OuterAlloc> inner_allocator_type; 26420cc2a42SHoward Hinnant 265*53ec0b4eSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 26620cc2a42SHoward Hinnant __scoped_allocator_storage() {} 26720cc2a42SHoward Hinnant 26820cc2a42SHoward Hinnant template <class _OuterA2, 26920cc2a42SHoward Hinnant class = typename enable_if< 27020cc2a42SHoward Hinnant is_constructible<outer_allocator_type, _OuterA2>::value 27120cc2a42SHoward Hinnant >::type> 272*53ec0b4eSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 27320cc2a42SHoward Hinnant __scoped_allocator_storage(_OuterA2&& __outerAlloc) 27420cc2a42SHoward Hinnant : outer_allocator_type(_STD::forward<_OuterA2>(__outerAlloc)) {} 27520cc2a42SHoward Hinnant 27620cc2a42SHoward Hinnant template <class _OuterA2, 27720cc2a42SHoward Hinnant class = typename enable_if< 27820cc2a42SHoward Hinnant is_constructible<outer_allocator_type, const _OuterA2&>::value 27920cc2a42SHoward Hinnant >::type> 280*53ec0b4eSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 28120cc2a42SHoward Hinnant __scoped_allocator_storage( 28220cc2a42SHoward Hinnant const __scoped_allocator_storage<_OuterA2>& __other) 28320cc2a42SHoward Hinnant : outer_allocator_type(__other.outer_allocator()) {} 28420cc2a42SHoward Hinnant 28520cc2a42SHoward Hinnant template <class _OuterA2, 28620cc2a42SHoward Hinnant class = typename enable_if< 28720cc2a42SHoward Hinnant is_constructible<outer_allocator_type, _OuterA2>::value 28820cc2a42SHoward Hinnant >::type> 289*53ec0b4eSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 29020cc2a42SHoward Hinnant __scoped_allocator_storage( 29120cc2a42SHoward Hinnant __scoped_allocator_storage<_OuterA2>&& __other) 29220cc2a42SHoward Hinnant : outer_allocator_type(_STD::move(__other.outer_allocator())) {} 29320cc2a42SHoward Hinnant 294*53ec0b4eSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 29520cc2a42SHoward Hinnant inner_allocator_type& inner_allocator() 29620cc2a42SHoward Hinnant {return static_cast<inner_allocator_type&>(*this);} 297*53ec0b4eSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 29820cc2a42SHoward Hinnant const inner_allocator_type& inner_allocator() const 29920cc2a42SHoward Hinnant {return static_cast<const inner_allocator_type&>(*this);} 30020cc2a42SHoward Hinnant 301*53ec0b4eSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 30220cc2a42SHoward Hinnant outer_allocator_type& outer_allocator() 30320cc2a42SHoward Hinnant {return static_cast<outer_allocator_type&>(*this);} 304*53ec0b4eSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 30520cc2a42SHoward Hinnant const outer_allocator_type& outer_allocator() const 30620cc2a42SHoward Hinnant {return static_cast<const outer_allocator_type&>(*this);} 30720cc2a42SHoward Hinnant 308*53ec0b4eSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 30920cc2a42SHoward Hinnant scoped_allocator_adaptor<outer_allocator_type> 31020cc2a42SHoward Hinnant select_on_container_copy_construction() const 31120cc2a42SHoward Hinnant {return scoped_allocator_adaptor<outer_allocator_type>( 31220cc2a42SHoward Hinnant allocator_traits<outer_allocator_type>:: 31320cc2a42SHoward Hinnant select_on_container_copy_construction(outer_allocator()) 31420cc2a42SHoward Hinnant );} 31520cc2a42SHoward Hinnant 31620cc2a42SHoward Hinnant __scoped_allocator_storage(const outer_allocator_type& __o, 31720cc2a42SHoward Hinnant const inner_allocator_type& __i); 31820cc2a42SHoward Hinnant 31920cc2a42SHoward Hinnant template <class...> friend class __scoped_allocator_storage; 32020cc2a42SHoward Hinnant}; 32120cc2a42SHoward Hinnant 32220cc2a42SHoward Hinnant// __outermost 32320cc2a42SHoward Hinnant 32420cc2a42SHoward Hinnanttemplate <class _Alloc> 32520cc2a42SHoward Hinnantdecltype(declval<_Alloc>().outer_allocator(), true_type()) 32620cc2a42SHoward Hinnant__has_outer_allocator_test(_Alloc&& __a); 32720cc2a42SHoward Hinnant 32820cc2a42SHoward Hinnanttemplate <class _Alloc> 32920cc2a42SHoward Hinnantfalse_type 33020cc2a42SHoward Hinnant__has_outer_allocator_test(const volatile _Alloc& __a); 33120cc2a42SHoward Hinnant 33220cc2a42SHoward Hinnanttemplate <class _Alloc> 33320cc2a42SHoward Hinnantstruct __has_outer_allocator 33420cc2a42SHoward Hinnant : public common_type 33520cc2a42SHoward Hinnant < 33620cc2a42SHoward Hinnant decltype(__has_outer_allocator_test(declval<_Alloc&>())) 33720cc2a42SHoward Hinnant >::type 33820cc2a42SHoward Hinnant{ 33920cc2a42SHoward Hinnant}; 34020cc2a42SHoward Hinnant 34120cc2a42SHoward Hinnanttemplate <class _Alloc, bool = __has_outer_allocator<_Alloc>::value> 34220cc2a42SHoward Hinnantstruct __outermost 34320cc2a42SHoward Hinnant{ 34420cc2a42SHoward Hinnant typedef _Alloc type; 345*53ec0b4eSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 34620cc2a42SHoward Hinnant type& operator()(type& __a) const {return __a;} 34720cc2a42SHoward Hinnant}; 34820cc2a42SHoward Hinnant 34920cc2a42SHoward Hinnanttemplate <class _Alloc> 35020cc2a42SHoward Hinnantstruct __outermost<_Alloc, true> 35120cc2a42SHoward Hinnant{ 35220cc2a42SHoward Hinnant typedef typename remove_reference 35320cc2a42SHoward Hinnant < 35420cc2a42SHoward Hinnant decltype(_STD::declval<_Alloc>().outer_allocator()) 35520cc2a42SHoward Hinnant >::type _OuterAlloc; 35620cc2a42SHoward Hinnant typedef typename __outermost<_OuterAlloc>::type type; 357*53ec0b4eSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 35820cc2a42SHoward Hinnant type& operator()(_Alloc& __a) const 35920cc2a42SHoward Hinnant {return __outermost<_OuterAlloc>()(__a.outer_allocator());} 36020cc2a42SHoward Hinnant}; 36120cc2a42SHoward Hinnant 36220cc2a42SHoward Hinnanttemplate <class _OuterAlloc, class... _InnerAllocs> 363*53ec0b4eSHoward Hinnantclass _LIBCPP_VISIBLE scoped_allocator_adaptor<_OuterAlloc, _InnerAllocs...> 36420cc2a42SHoward Hinnant : public __scoped_allocator_storage<_OuterAlloc, _InnerAllocs...> 36520cc2a42SHoward Hinnant{ 36620cc2a42SHoward Hinnant typedef __scoped_allocator_storage<_OuterAlloc, _InnerAllocs...> base; 36720cc2a42SHoward Hinnant typedef allocator_traits<_OuterAlloc> _OuterTraits; 36820cc2a42SHoward Hinnantpublic: 36920cc2a42SHoward Hinnant typedef _OuterAlloc outer_allocator_type; 37020cc2a42SHoward Hinnant typedef typename base::inner_allocator_type inner_allocator_type; 37120cc2a42SHoward Hinnant typedef typename _OuterTraits::size_type size_type; 37220cc2a42SHoward Hinnant typedef typename _OuterTraits::difference_type difference_type; 37320cc2a42SHoward Hinnant typedef typename _OuterTraits::pointer pointer; 37420cc2a42SHoward Hinnant typedef typename _OuterTraits::const_pointer const_pointer; 37520cc2a42SHoward Hinnant typedef typename _OuterTraits::void_pointer void_pointer; 37620cc2a42SHoward Hinnant typedef typename _OuterTraits::const_void_pointer const_void_pointer; 37720cc2a42SHoward Hinnant 37820cc2a42SHoward Hinnant typedef integral_constant 37920cc2a42SHoward Hinnant < 38020cc2a42SHoward Hinnant bool, 38120cc2a42SHoward Hinnant __get_poc_copy_assignment<outer_allocator_type, 38220cc2a42SHoward Hinnant _InnerAllocs...>::value 38320cc2a42SHoward Hinnant > propagate_on_container_copy_assignment; 38420cc2a42SHoward Hinnant typedef integral_constant 38520cc2a42SHoward Hinnant < 38620cc2a42SHoward Hinnant bool, 38720cc2a42SHoward Hinnant __get_poc_move_assignment<outer_allocator_type, 38820cc2a42SHoward Hinnant _InnerAllocs...>::value 38920cc2a42SHoward Hinnant > propagate_on_container_move_assignment; 39020cc2a42SHoward Hinnant typedef integral_constant 39120cc2a42SHoward Hinnant < 39220cc2a42SHoward Hinnant bool, 39320cc2a42SHoward Hinnant __get_poc_swap<outer_allocator_type, _InnerAllocs...>::value 39420cc2a42SHoward Hinnant > propagate_on_container_swap; 39520cc2a42SHoward Hinnant 39620cc2a42SHoward Hinnant template <class _Tp> 39720cc2a42SHoward Hinnant struct rebind 39820cc2a42SHoward Hinnant { 39920cc2a42SHoward Hinnant typedef scoped_allocator_adaptor 40020cc2a42SHoward Hinnant < 40120cc2a42SHoward Hinnant typename _OuterTraits::template rebind_alloc<_Tp>, _InnerAllocs... 40220cc2a42SHoward Hinnant > other; 40320cc2a42SHoward Hinnant }; 40420cc2a42SHoward Hinnant 405*53ec0b4eSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 40620cc2a42SHoward Hinnant scoped_allocator_adaptor() {} 40720cc2a42SHoward Hinnant template <class _OuterA2, 40820cc2a42SHoward Hinnant class = typename enable_if< 40920cc2a42SHoward Hinnant is_constructible<outer_allocator_type, _OuterA2>::value 41020cc2a42SHoward Hinnant >::type> 411*53ec0b4eSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 41220cc2a42SHoward Hinnant scoped_allocator_adaptor(_OuterA2&& __outerAlloc, 41320cc2a42SHoward Hinnant const _InnerAllocs& ...__innerAllocs) 41420cc2a42SHoward Hinnant : base(_STD::forward<_OuterA2>(__outerAlloc), __innerAllocs...) {} 41520cc2a42SHoward Hinnant // scoped_allocator_adaptor(const scoped_allocator_adaptor& __other) = default; 41620cc2a42SHoward Hinnant template <class _OuterA2, 41720cc2a42SHoward Hinnant class = typename enable_if< 41820cc2a42SHoward Hinnant is_constructible<outer_allocator_type, const _OuterA2&>::value 41920cc2a42SHoward Hinnant >::type> 420*53ec0b4eSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 42120cc2a42SHoward Hinnant scoped_allocator_adaptor( 42220cc2a42SHoward Hinnant const scoped_allocator_adaptor<_OuterA2, _InnerAllocs...>& __other) 42320cc2a42SHoward Hinnant : base(__other) {} 42420cc2a42SHoward Hinnant template <class _OuterA2, 42520cc2a42SHoward Hinnant class = typename enable_if< 42620cc2a42SHoward Hinnant is_constructible<outer_allocator_type, _OuterA2>::value 42720cc2a42SHoward Hinnant >::type> 428*53ec0b4eSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 42920cc2a42SHoward Hinnant scoped_allocator_adaptor( 43020cc2a42SHoward Hinnant scoped_allocator_adaptor<_OuterA2, _InnerAllocs...>&& __other) 43120cc2a42SHoward Hinnant : base(_STD::move(__other)) {} 43220cc2a42SHoward Hinnant 43320cc2a42SHoward Hinnant // ~scoped_allocator_adaptor() = default; 43420cc2a42SHoward Hinnant 435*53ec0b4eSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 43620cc2a42SHoward Hinnant inner_allocator_type& inner_allocator() 43720cc2a42SHoward Hinnant {return base::inner_allocator();} 438*53ec0b4eSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 43920cc2a42SHoward Hinnant const inner_allocator_type& inner_allocator() const 44020cc2a42SHoward Hinnant {return base::inner_allocator();} 44120cc2a42SHoward Hinnant 442*53ec0b4eSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 44320cc2a42SHoward Hinnant outer_allocator_type& outer_allocator() 44420cc2a42SHoward Hinnant {return base::outer_allocator();} 445*53ec0b4eSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 44620cc2a42SHoward Hinnant const outer_allocator_type& outer_allocator() const 44720cc2a42SHoward Hinnant {return base::outer_allocator();} 44820cc2a42SHoward Hinnant 449*53ec0b4eSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 45020cc2a42SHoward Hinnant pointer allocate(size_type __n) 45120cc2a42SHoward Hinnant {return allocator_traits<outer_allocator_type>:: 45220cc2a42SHoward Hinnant allocate(outer_allocator(), __n);} 453*53ec0b4eSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 45420cc2a42SHoward Hinnant pointer allocate(size_type __n, const_void_pointer __hint) 45520cc2a42SHoward Hinnant {return allocator_traits<outer_allocator_type>:: 45620cc2a42SHoward Hinnant allocate(outer_allocator(), __n, __hint);} 45720cc2a42SHoward Hinnant 458*53ec0b4eSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 45920cc2a42SHoward Hinnant void deallocate(pointer __p, size_type __n) 46020cc2a42SHoward Hinnant {allocator_traits<outer_allocator_type>:: 46120cc2a42SHoward Hinnant deallocate(outer_allocator(), __p, __n);} 46220cc2a42SHoward Hinnant 463*53ec0b4eSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 46420cc2a42SHoward Hinnant size_type max_size() const 465*53ec0b4eSHoward Hinnant {return allocator_traits<outer_allocator_type>::max_size(outer_allocator());} 46620cc2a42SHoward Hinnant 46720cc2a42SHoward Hinnant template <class _Tp, class... _Args> 468*53ec0b4eSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 46920cc2a42SHoward Hinnant void construct(_Tp* __p, _Args&& ...__args) 47020cc2a42SHoward Hinnant {__construct(__uses_alloc_ctor<_Tp, inner_allocator_type, _Args...>(), 47120cc2a42SHoward Hinnant __p, _STD::forward<_Args>(__args)...);} 47220cc2a42SHoward Hinnant template <class _Tp> 473*53ec0b4eSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 47420cc2a42SHoward Hinnant void destroy(_Tp* __p) 47520cc2a42SHoward Hinnant { 47620cc2a42SHoward Hinnant typedef __outermost<outer_allocator_type> _OM; 47720cc2a42SHoward Hinnant allocator_traits<typename _OM::type>:: 47820cc2a42SHoward Hinnant destroy(_OM()(outer_allocator()), __p); 47920cc2a42SHoward Hinnant } 48020cc2a42SHoward Hinnant 481*53ec0b4eSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 48220cc2a42SHoward Hinnant scoped_allocator_adaptor select_on_container_copy_construction() const 48320cc2a42SHoward Hinnant {return base::select_on_container_copy_construction();} 48420cc2a42SHoward Hinnant 48520cc2a42SHoward Hinnantprivate: 48620cc2a42SHoward Hinnant 48720cc2a42SHoward Hinnant template <class _OuterA2, 48820cc2a42SHoward Hinnant class = typename enable_if< 48920cc2a42SHoward Hinnant is_constructible<outer_allocator_type, _OuterA2>::value 49020cc2a42SHoward Hinnant >::type> 491*53ec0b4eSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 49220cc2a42SHoward Hinnant scoped_allocator_adaptor(_OuterA2&& __o, 49320cc2a42SHoward Hinnant const inner_allocator_type& __i) 49420cc2a42SHoward Hinnant : base(_STD::forward<_OuterA2>(__o), __i) {} 49520cc2a42SHoward Hinnant 49620cc2a42SHoward Hinnant template <class _Tp, class... _Args> 497*53ec0b4eSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 49820cc2a42SHoward Hinnant void __construct(integral_constant<int, 0>, _Tp* __p, _Args&& ...__args) 49920cc2a42SHoward Hinnant { 50020cc2a42SHoward Hinnant typedef __outermost<outer_allocator_type> _OM; 50120cc2a42SHoward Hinnant allocator_traits<typename _OM::type>::construct 50220cc2a42SHoward Hinnant ( 50320cc2a42SHoward Hinnant _OM()(outer_allocator()), 50420cc2a42SHoward Hinnant __p, 50520cc2a42SHoward Hinnant _STD::forward<_Args>(__args)... 50620cc2a42SHoward Hinnant ); 50720cc2a42SHoward Hinnant } 50820cc2a42SHoward Hinnant 50920cc2a42SHoward Hinnant template <class _Tp, class... _Args> 510*53ec0b4eSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 51120cc2a42SHoward Hinnant void __construct(integral_constant<int, 1>, _Tp* __p, _Args&& ...__args) 51220cc2a42SHoward Hinnant { 51320cc2a42SHoward Hinnant typedef __outermost<outer_allocator_type> _OM; 51420cc2a42SHoward Hinnant allocator_traits<typename _OM::type>::construct 51520cc2a42SHoward Hinnant ( 51620cc2a42SHoward Hinnant _OM()(outer_allocator()), 51720cc2a42SHoward Hinnant __p, 51820cc2a42SHoward Hinnant allocator_arg, 51920cc2a42SHoward Hinnant inner_allocator(), 52020cc2a42SHoward Hinnant _STD::forward<_Args>(__args)... 52120cc2a42SHoward Hinnant ); 52220cc2a42SHoward Hinnant } 52320cc2a42SHoward Hinnant 52420cc2a42SHoward Hinnant template <class _Tp, class... _Args> 525*53ec0b4eSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 52620cc2a42SHoward Hinnant void __construct(integral_constant<int, 2>, _Tp* __p, _Args&& ...__args) 52720cc2a42SHoward Hinnant { 52820cc2a42SHoward Hinnant typedef __outermost<outer_allocator_type> _OM; 52920cc2a42SHoward Hinnant allocator_traits<typename _OM::type>::construct 53020cc2a42SHoward Hinnant ( 53120cc2a42SHoward Hinnant _OM()(outer_allocator()), 53220cc2a42SHoward Hinnant __p, 53320cc2a42SHoward Hinnant _STD::forward<_Args>(__args)..., 53420cc2a42SHoward Hinnant inner_allocator() 53520cc2a42SHoward Hinnant ); 53620cc2a42SHoward Hinnant } 53720cc2a42SHoward Hinnant 53820cc2a42SHoward Hinnant template <class...> friend class __scoped_allocator_storage; 53920cc2a42SHoward Hinnant}; 54020cc2a42SHoward Hinnant 54120cc2a42SHoward Hinnanttemplate <class _OuterA1, class _OuterA2> 54220cc2a42SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 54320cc2a42SHoward Hinnantbool 54420cc2a42SHoward Hinnantoperator==(const scoped_allocator_adaptor<_OuterA1>& __a, 54520cc2a42SHoward Hinnant const scoped_allocator_adaptor<_OuterA2>& __b) 54620cc2a42SHoward Hinnant{ 54720cc2a42SHoward Hinnant return __a.outer_allocator() == __b.outer_allocator(); 54820cc2a42SHoward Hinnant} 54920cc2a42SHoward Hinnant 55020cc2a42SHoward Hinnanttemplate <class _OuterA1, class _OuterA2, class... _InnerAllocs> 55120cc2a42SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 55220cc2a42SHoward Hinnantbool 55320cc2a42SHoward Hinnantoperator==(const scoped_allocator_adaptor<_OuterA1, _InnerAllocs...>& __a, 55420cc2a42SHoward Hinnant const scoped_allocator_adaptor<_OuterA2, _InnerAllocs...>& __b) 55520cc2a42SHoward Hinnant{ 55620cc2a42SHoward Hinnant return __a.outer_allocator() == __b.outer_allocator() && 55720cc2a42SHoward Hinnant __a.inner_allocator() == __b.inner_allocator(); 55820cc2a42SHoward Hinnant} 55920cc2a42SHoward Hinnant 56020cc2a42SHoward Hinnanttemplate <class _OuterA1, class _OuterA2, class... _InnerAllocs> 56120cc2a42SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 56220cc2a42SHoward Hinnantbool 56320cc2a42SHoward Hinnantoperator!=(const scoped_allocator_adaptor<_OuterA1, _InnerAllocs...>& __a, 56420cc2a42SHoward Hinnant const scoped_allocator_adaptor<_OuterA2, _InnerAllocs...>& __b) 56520cc2a42SHoward Hinnant{ 56620cc2a42SHoward Hinnant return !(__a == __b); 56720cc2a42SHoward Hinnant} 56820cc2a42SHoward Hinnant 5697609c9b6SHoward Hinnant#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_ADVANCED_SFINAE) 57020cc2a42SHoward Hinnant 57120cc2a42SHoward Hinnant_LIBCPP_END_NAMESPACE_STD 57220cc2a42SHoward Hinnant 57320cc2a42SHoward Hinnant#endif // _LIBCPP_SCOPED_ALLOCATOR 574