1*58b9f456SAndroid Build Coastguard Worker// -*- C++ -*- 2*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_SPLIT_BUFFER 3*58b9f456SAndroid Build Coastguard Worker#define _LIBCPP_SPLIT_BUFFER 4*58b9f456SAndroid Build Coastguard Worker 5*58b9f456SAndroid Build Coastguard Worker#include <__config> 6*58b9f456SAndroid Build Coastguard Worker#include <type_traits> 7*58b9f456SAndroid Build Coastguard Worker#include <algorithm> 8*58b9f456SAndroid Build Coastguard Worker 9*58b9f456SAndroid Build Coastguard Worker#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 10*58b9f456SAndroid Build Coastguard Worker#pragma GCC system_header 11*58b9f456SAndroid Build Coastguard Worker#endif 12*58b9f456SAndroid Build Coastguard Worker 13*58b9f456SAndroid Build Coastguard Worker_LIBCPP_PUSH_MACROS 14*58b9f456SAndroid Build Coastguard Worker#include <__undef_macros> 15*58b9f456SAndroid Build Coastguard Worker 16*58b9f456SAndroid Build Coastguard Worker 17*58b9f456SAndroid Build Coastguard Worker_LIBCPP_BEGIN_NAMESPACE_STD 18*58b9f456SAndroid Build Coastguard Worker 19*58b9f456SAndroid Build Coastguard Workertemplate <bool> 20*58b9f456SAndroid Build Coastguard Workerclass __split_buffer_common 21*58b9f456SAndroid Build Coastguard Worker{ 22*58b9f456SAndroid Build Coastguard Workerprotected: 23*58b9f456SAndroid Build Coastguard Worker void __throw_length_error() const; 24*58b9f456SAndroid Build Coastguard Worker void __throw_out_of_range() const; 25*58b9f456SAndroid Build Coastguard Worker}; 26*58b9f456SAndroid Build Coastguard Worker 27*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Allocator = allocator<_Tp> > 28*58b9f456SAndroid Build Coastguard Workerstruct __split_buffer 29*58b9f456SAndroid Build Coastguard Worker : private __split_buffer_common<true> 30*58b9f456SAndroid Build Coastguard Worker{ 31*58b9f456SAndroid Build Coastguard Workerprivate: 32*58b9f456SAndroid Build Coastguard Worker __split_buffer(const __split_buffer&); 33*58b9f456SAndroid Build Coastguard Worker __split_buffer& operator=(const __split_buffer&); 34*58b9f456SAndroid Build Coastguard Workerpublic: 35*58b9f456SAndroid Build Coastguard Worker typedef _Tp value_type; 36*58b9f456SAndroid Build Coastguard Worker typedef _Allocator allocator_type; 37*58b9f456SAndroid Build Coastguard Worker typedef typename remove_reference<allocator_type>::type __alloc_rr; 38*58b9f456SAndroid Build Coastguard Worker typedef allocator_traits<__alloc_rr> __alloc_traits; 39*58b9f456SAndroid Build Coastguard Worker typedef value_type& reference; 40*58b9f456SAndroid Build Coastguard Worker typedef const value_type& const_reference; 41*58b9f456SAndroid Build Coastguard Worker typedef typename __alloc_traits::size_type size_type; 42*58b9f456SAndroid Build Coastguard Worker typedef typename __alloc_traits::difference_type difference_type; 43*58b9f456SAndroid Build Coastguard Worker typedef typename __alloc_traits::pointer pointer; 44*58b9f456SAndroid Build Coastguard Worker typedef typename __alloc_traits::const_pointer const_pointer; 45*58b9f456SAndroid Build Coastguard Worker typedef pointer iterator; 46*58b9f456SAndroid Build Coastguard Worker typedef const_pointer const_iterator; 47*58b9f456SAndroid Build Coastguard Worker 48*58b9f456SAndroid Build Coastguard Worker pointer __first_; 49*58b9f456SAndroid Build Coastguard Worker pointer __begin_; 50*58b9f456SAndroid Build Coastguard Worker pointer __end_; 51*58b9f456SAndroid Build Coastguard Worker __compressed_pair<pointer, allocator_type> __end_cap_; 52*58b9f456SAndroid Build Coastguard Worker 53*58b9f456SAndroid Build Coastguard Worker typedef typename add_lvalue_reference<allocator_type>::type __alloc_ref; 54*58b9f456SAndroid Build Coastguard Worker typedef typename add_lvalue_reference<allocator_type>::type __alloc_const_ref; 55*58b9f456SAndroid Build Coastguard Worker 56*58b9f456SAndroid Build Coastguard Worker _LIBCPP_INLINE_VISIBILITY __alloc_rr& __alloc() _NOEXCEPT {return __end_cap_.second();} 57*58b9f456SAndroid Build Coastguard Worker _LIBCPP_INLINE_VISIBILITY const __alloc_rr& __alloc() const _NOEXCEPT {return __end_cap_.second();} 58*58b9f456SAndroid Build Coastguard Worker _LIBCPP_INLINE_VISIBILITY pointer& __end_cap() _NOEXCEPT {return __end_cap_.first();} 59*58b9f456SAndroid Build Coastguard Worker _LIBCPP_INLINE_VISIBILITY const pointer& __end_cap() const _NOEXCEPT {return __end_cap_.first();} 60*58b9f456SAndroid Build Coastguard Worker 61*58b9f456SAndroid Build Coastguard Worker _LIBCPP_INLINE_VISIBILITY 62*58b9f456SAndroid Build Coastguard Worker __split_buffer() 63*58b9f456SAndroid Build Coastguard Worker _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value); 64*58b9f456SAndroid Build Coastguard Worker _LIBCPP_INLINE_VISIBILITY 65*58b9f456SAndroid Build Coastguard Worker explicit __split_buffer(__alloc_rr& __a); 66*58b9f456SAndroid Build Coastguard Worker _LIBCPP_INLINE_VISIBILITY 67*58b9f456SAndroid Build Coastguard Worker explicit __split_buffer(const __alloc_rr& __a); 68*58b9f456SAndroid Build Coastguard Worker __split_buffer(size_type __cap, size_type __start, __alloc_rr& __a); 69*58b9f456SAndroid Build Coastguard Worker ~__split_buffer(); 70*58b9f456SAndroid Build Coastguard Worker 71*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_CXX03_LANG 72*58b9f456SAndroid Build Coastguard Worker __split_buffer(__split_buffer&& __c) 73*58b9f456SAndroid Build Coastguard Worker _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); 74*58b9f456SAndroid Build Coastguard Worker __split_buffer(__split_buffer&& __c, const __alloc_rr& __a); 75*58b9f456SAndroid Build Coastguard Worker __split_buffer& operator=(__split_buffer&& __c) 76*58b9f456SAndroid Build Coastguard Worker _NOEXCEPT_((__alloc_traits::propagate_on_container_move_assignment::value && 77*58b9f456SAndroid Build Coastguard Worker is_nothrow_move_assignable<allocator_type>::value) || 78*58b9f456SAndroid Build Coastguard Worker !__alloc_traits::propagate_on_container_move_assignment::value); 79*58b9f456SAndroid Build Coastguard Worker#endif // _LIBCPP_CXX03_LANG 80*58b9f456SAndroid Build Coastguard Worker 81*58b9f456SAndroid Build Coastguard Worker _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT {return __begin_;} 82*58b9f456SAndroid Build Coastguard Worker _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT {return __begin_;} 83*58b9f456SAndroid Build Coastguard Worker _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT {return __end_;} 84*58b9f456SAndroid Build Coastguard Worker _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT {return __end_;} 85*58b9f456SAndroid Build Coastguard Worker 86*58b9f456SAndroid Build Coastguard Worker _LIBCPP_INLINE_VISIBILITY 87*58b9f456SAndroid Build Coastguard Worker void clear() _NOEXCEPT 88*58b9f456SAndroid Build Coastguard Worker {__destruct_at_end(__begin_);} 89*58b9f456SAndroid Build Coastguard Worker _LIBCPP_INLINE_VISIBILITY size_type size() const {return static_cast<size_type>(__end_ - __begin_);} 90*58b9f456SAndroid Build Coastguard Worker _LIBCPP_INLINE_VISIBILITY bool empty() const {return __end_ == __begin_;} 91*58b9f456SAndroid Build Coastguard Worker _LIBCPP_INLINE_VISIBILITY size_type capacity() const {return static_cast<size_type>(__end_cap() - __first_);} 92*58b9f456SAndroid Build Coastguard Worker _LIBCPP_INLINE_VISIBILITY size_type __front_spare() const {return static_cast<size_type>(__begin_ - __first_);} 93*58b9f456SAndroid Build Coastguard Worker _LIBCPP_INLINE_VISIBILITY size_type __back_spare() const {return static_cast<size_type>(__end_cap() - __end_);} 94*58b9f456SAndroid Build Coastguard Worker 95*58b9f456SAndroid Build Coastguard Worker _LIBCPP_INLINE_VISIBILITY reference front() {return *__begin_;} 96*58b9f456SAndroid Build Coastguard Worker _LIBCPP_INLINE_VISIBILITY const_reference front() const {return *__begin_;} 97*58b9f456SAndroid Build Coastguard Worker _LIBCPP_INLINE_VISIBILITY reference back() {return *(__end_ - 1);} 98*58b9f456SAndroid Build Coastguard Worker _LIBCPP_INLINE_VISIBILITY const_reference back() const {return *(__end_ - 1);} 99*58b9f456SAndroid Build Coastguard Worker 100*58b9f456SAndroid Build Coastguard Worker void reserve(size_type __n); 101*58b9f456SAndroid Build Coastguard Worker void shrink_to_fit() _NOEXCEPT; 102*58b9f456SAndroid Build Coastguard Worker void push_front(const_reference __x); 103*58b9f456SAndroid Build Coastguard Worker _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x); 104*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_CXX03_LANG 105*58b9f456SAndroid Build Coastguard Worker void push_front(value_type&& __x); 106*58b9f456SAndroid Build Coastguard Worker void push_back(value_type&& __x); 107*58b9f456SAndroid Build Coastguard Worker template <class... _Args> 108*58b9f456SAndroid Build Coastguard Worker void emplace_back(_Args&&... __args); 109*58b9f456SAndroid Build Coastguard Worker#endif // !defined(_LIBCPP_CXX03_LANG) 110*58b9f456SAndroid Build Coastguard Worker 111*58b9f456SAndroid Build Coastguard Worker _LIBCPP_INLINE_VISIBILITY void pop_front() {__destruct_at_begin(__begin_+1);} 112*58b9f456SAndroid Build Coastguard Worker _LIBCPP_INLINE_VISIBILITY void pop_back() {__destruct_at_end(__end_-1);} 113*58b9f456SAndroid Build Coastguard Worker 114*58b9f456SAndroid Build Coastguard Worker void __construct_at_end(size_type __n); 115*58b9f456SAndroid Build Coastguard Worker void __construct_at_end(size_type __n, const_reference __x); 116*58b9f456SAndroid Build Coastguard Worker template <class _InputIter> 117*58b9f456SAndroid Build Coastguard Worker typename enable_if 118*58b9f456SAndroid Build Coastguard Worker < 119*58b9f456SAndroid Build Coastguard Worker __is_input_iterator<_InputIter>::value && 120*58b9f456SAndroid Build Coastguard Worker !__is_forward_iterator<_InputIter>::value, 121*58b9f456SAndroid Build Coastguard Worker void 122*58b9f456SAndroid Build Coastguard Worker >::type 123*58b9f456SAndroid Build Coastguard Worker __construct_at_end(_InputIter __first, _InputIter __last); 124*58b9f456SAndroid Build Coastguard Worker template <class _ForwardIterator> 125*58b9f456SAndroid Build Coastguard Worker typename enable_if 126*58b9f456SAndroid Build Coastguard Worker < 127*58b9f456SAndroid Build Coastguard Worker __is_forward_iterator<_ForwardIterator>::value, 128*58b9f456SAndroid Build Coastguard Worker void 129*58b9f456SAndroid Build Coastguard Worker >::type 130*58b9f456SAndroid Build Coastguard Worker __construct_at_end(_ForwardIterator __first, _ForwardIterator __last); 131*58b9f456SAndroid Build Coastguard Worker 132*58b9f456SAndroid Build Coastguard Worker _LIBCPP_INLINE_VISIBILITY void __destruct_at_begin(pointer __new_begin) 133*58b9f456SAndroid Build Coastguard Worker {__destruct_at_begin(__new_begin, is_trivially_destructible<value_type>());} 134*58b9f456SAndroid Build Coastguard Worker _LIBCPP_INLINE_VISIBILITY 135*58b9f456SAndroid Build Coastguard Worker void __destruct_at_begin(pointer __new_begin, false_type); 136*58b9f456SAndroid Build Coastguard Worker _LIBCPP_INLINE_VISIBILITY 137*58b9f456SAndroid Build Coastguard Worker void __destruct_at_begin(pointer __new_begin, true_type); 138*58b9f456SAndroid Build Coastguard Worker 139*58b9f456SAndroid Build Coastguard Worker _LIBCPP_INLINE_VISIBILITY 140*58b9f456SAndroid Build Coastguard Worker void __destruct_at_end(pointer __new_last) _NOEXCEPT 141*58b9f456SAndroid Build Coastguard Worker {__destruct_at_end(__new_last, false_type());} 142*58b9f456SAndroid Build Coastguard Worker _LIBCPP_INLINE_VISIBILITY 143*58b9f456SAndroid Build Coastguard Worker void __destruct_at_end(pointer __new_last, false_type) _NOEXCEPT; 144*58b9f456SAndroid Build Coastguard Worker _LIBCPP_INLINE_VISIBILITY 145*58b9f456SAndroid Build Coastguard Worker void __destruct_at_end(pointer __new_last, true_type) _NOEXCEPT; 146*58b9f456SAndroid Build Coastguard Worker 147*58b9f456SAndroid Build Coastguard Worker void swap(__split_buffer& __x) 148*58b9f456SAndroid Build Coastguard Worker _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value|| 149*58b9f456SAndroid Build Coastguard Worker __is_nothrow_swappable<__alloc_rr>::value); 150*58b9f456SAndroid Build Coastguard Worker 151*58b9f456SAndroid Build Coastguard Worker bool __invariants() const; 152*58b9f456SAndroid Build Coastguard Worker 153*58b9f456SAndroid Build Coastguard Workerprivate: 154*58b9f456SAndroid Build Coastguard Worker _LIBCPP_INLINE_VISIBILITY 155*58b9f456SAndroid Build Coastguard Worker void __move_assign_alloc(__split_buffer& __c, true_type) 156*58b9f456SAndroid Build Coastguard Worker _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) 157*58b9f456SAndroid Build Coastguard Worker { 158*58b9f456SAndroid Build Coastguard Worker __alloc() = _VSTD::move(__c.__alloc()); 159*58b9f456SAndroid Build Coastguard Worker } 160*58b9f456SAndroid Build Coastguard Worker 161*58b9f456SAndroid Build Coastguard Worker _LIBCPP_INLINE_VISIBILITY 162*58b9f456SAndroid Build Coastguard Worker void __move_assign_alloc(__split_buffer&, false_type) _NOEXCEPT 163*58b9f456SAndroid Build Coastguard Worker {} 164*58b9f456SAndroid Build Coastguard Worker}; 165*58b9f456SAndroid Build Coastguard Worker 166*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Allocator> 167*58b9f456SAndroid Build Coastguard Workerbool 168*58b9f456SAndroid Build Coastguard Worker__split_buffer<_Tp, _Allocator>::__invariants() const 169*58b9f456SAndroid Build Coastguard Worker{ 170*58b9f456SAndroid Build Coastguard Worker if (__first_ == nullptr) 171*58b9f456SAndroid Build Coastguard Worker { 172*58b9f456SAndroid Build Coastguard Worker if (__begin_ != nullptr) 173*58b9f456SAndroid Build Coastguard Worker return false; 174*58b9f456SAndroid Build Coastguard Worker if (__end_ != nullptr) 175*58b9f456SAndroid Build Coastguard Worker return false; 176*58b9f456SAndroid Build Coastguard Worker if (__end_cap() != nullptr) 177*58b9f456SAndroid Build Coastguard Worker return false; 178*58b9f456SAndroid Build Coastguard Worker } 179*58b9f456SAndroid Build Coastguard Worker else 180*58b9f456SAndroid Build Coastguard Worker { 181*58b9f456SAndroid Build Coastguard Worker if (__begin_ < __first_) 182*58b9f456SAndroid Build Coastguard Worker return false; 183*58b9f456SAndroid Build Coastguard Worker if (__end_ < __begin_) 184*58b9f456SAndroid Build Coastguard Worker return false; 185*58b9f456SAndroid Build Coastguard Worker if (__end_cap() < __end_) 186*58b9f456SAndroid Build Coastguard Worker return false; 187*58b9f456SAndroid Build Coastguard Worker } 188*58b9f456SAndroid Build Coastguard Worker return true; 189*58b9f456SAndroid Build Coastguard Worker} 190*58b9f456SAndroid Build Coastguard Worker 191*58b9f456SAndroid Build Coastguard Worker// Default constructs __n objects starting at __end_ 192*58b9f456SAndroid Build Coastguard Worker// throws if construction throws 193*58b9f456SAndroid Build Coastguard Worker// Precondition: __n > 0 194*58b9f456SAndroid Build Coastguard Worker// Precondition: size() + __n <= capacity() 195*58b9f456SAndroid Build Coastguard Worker// Postcondition: size() == size() + __n 196*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Allocator> 197*58b9f456SAndroid Build Coastguard Workervoid 198*58b9f456SAndroid Build Coastguard Worker__split_buffer<_Tp, _Allocator>::__construct_at_end(size_type __n) 199*58b9f456SAndroid Build Coastguard Worker{ 200*58b9f456SAndroid Build Coastguard Worker __alloc_rr& __a = this->__alloc(); 201*58b9f456SAndroid Build Coastguard Worker do 202*58b9f456SAndroid Build Coastguard Worker { 203*58b9f456SAndroid Build Coastguard Worker __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_)); 204*58b9f456SAndroid Build Coastguard Worker ++this->__end_; 205*58b9f456SAndroid Build Coastguard Worker --__n; 206*58b9f456SAndroid Build Coastguard Worker } while (__n > 0); 207*58b9f456SAndroid Build Coastguard Worker} 208*58b9f456SAndroid Build Coastguard Worker 209*58b9f456SAndroid Build Coastguard Worker// Copy constructs __n objects starting at __end_ from __x 210*58b9f456SAndroid Build Coastguard Worker// throws if construction throws 211*58b9f456SAndroid Build Coastguard Worker// Precondition: __n > 0 212*58b9f456SAndroid Build Coastguard Worker// Precondition: size() + __n <= capacity() 213*58b9f456SAndroid Build Coastguard Worker// Postcondition: size() == old size() + __n 214*58b9f456SAndroid Build Coastguard Worker// Postcondition: [i] == __x for all i in [size() - __n, __n) 215*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Allocator> 216*58b9f456SAndroid Build Coastguard Workervoid 217*58b9f456SAndroid Build Coastguard Worker__split_buffer<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x) 218*58b9f456SAndroid Build Coastguard Worker{ 219*58b9f456SAndroid Build Coastguard Worker __alloc_rr& __a = this->__alloc(); 220*58b9f456SAndroid Build Coastguard Worker do 221*58b9f456SAndroid Build Coastguard Worker { 222*58b9f456SAndroid Build Coastguard Worker __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), __x); 223*58b9f456SAndroid Build Coastguard Worker ++this->__end_; 224*58b9f456SAndroid Build Coastguard Worker --__n; 225*58b9f456SAndroid Build Coastguard Worker } while (__n > 0); 226*58b9f456SAndroid Build Coastguard Worker} 227*58b9f456SAndroid Build Coastguard Worker 228*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Allocator> 229*58b9f456SAndroid Build Coastguard Workertemplate <class _InputIter> 230*58b9f456SAndroid Build Coastguard Workertypename enable_if 231*58b9f456SAndroid Build Coastguard Worker< 232*58b9f456SAndroid Build Coastguard Worker __is_input_iterator<_InputIter>::value && 233*58b9f456SAndroid Build Coastguard Worker !__is_forward_iterator<_InputIter>::value, 234*58b9f456SAndroid Build Coastguard Worker void 235*58b9f456SAndroid Build Coastguard Worker>::type 236*58b9f456SAndroid Build Coastguard Worker__split_buffer<_Tp, _Allocator>::__construct_at_end(_InputIter __first, _InputIter __last) 237*58b9f456SAndroid Build Coastguard Worker{ 238*58b9f456SAndroid Build Coastguard Worker __alloc_rr& __a = this->__alloc(); 239*58b9f456SAndroid Build Coastguard Worker for (; __first != __last; ++__first) 240*58b9f456SAndroid Build Coastguard Worker { 241*58b9f456SAndroid Build Coastguard Worker if (__end_ == __end_cap()) 242*58b9f456SAndroid Build Coastguard Worker { 243*58b9f456SAndroid Build Coastguard Worker size_type __old_cap = __end_cap() - __first_; 244*58b9f456SAndroid Build Coastguard Worker size_type __new_cap = _VSTD::max<size_type>(2 * __old_cap, 8); 245*58b9f456SAndroid Build Coastguard Worker __split_buffer __buf(__new_cap, 0, __a); 246*58b9f456SAndroid Build Coastguard Worker for (pointer __p = __begin_; __p != __end_; ++__p, ++__buf.__end_) 247*58b9f456SAndroid Build Coastguard Worker __alloc_traits::construct(__buf.__alloc(), 248*58b9f456SAndroid Build Coastguard Worker _VSTD::__to_raw_pointer(__buf.__end_), _VSTD::move(*__p)); 249*58b9f456SAndroid Build Coastguard Worker swap(__buf); 250*58b9f456SAndroid Build Coastguard Worker } 251*58b9f456SAndroid Build Coastguard Worker __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), *__first); 252*58b9f456SAndroid Build Coastguard Worker ++this->__end_; 253*58b9f456SAndroid Build Coastguard Worker } 254*58b9f456SAndroid Build Coastguard Worker} 255*58b9f456SAndroid Build Coastguard Worker 256*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Allocator> 257*58b9f456SAndroid Build Coastguard Workertemplate <class _ForwardIterator> 258*58b9f456SAndroid Build Coastguard Workertypename enable_if 259*58b9f456SAndroid Build Coastguard Worker< 260*58b9f456SAndroid Build Coastguard Worker __is_forward_iterator<_ForwardIterator>::value, 261*58b9f456SAndroid Build Coastguard Worker void 262*58b9f456SAndroid Build Coastguard Worker>::type 263*58b9f456SAndroid Build Coastguard Worker__split_buffer<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last) 264*58b9f456SAndroid Build Coastguard Worker{ 265*58b9f456SAndroid Build Coastguard Worker __alloc_rr& __a = this->__alloc(); 266*58b9f456SAndroid Build Coastguard Worker for (; __first != __last; ++__first) 267*58b9f456SAndroid Build Coastguard Worker { 268*58b9f456SAndroid Build Coastguard Worker __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), *__first); 269*58b9f456SAndroid Build Coastguard Worker ++this->__end_; 270*58b9f456SAndroid Build Coastguard Worker } 271*58b9f456SAndroid Build Coastguard Worker} 272*58b9f456SAndroid Build Coastguard Worker 273*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Allocator> 274*58b9f456SAndroid Build Coastguard Workerinline 275*58b9f456SAndroid Build Coastguard Workervoid 276*58b9f456SAndroid Build Coastguard Worker__split_buffer<_Tp, _Allocator>::__destruct_at_begin(pointer __new_begin, false_type) 277*58b9f456SAndroid Build Coastguard Worker{ 278*58b9f456SAndroid Build Coastguard Worker while (__begin_ != __new_begin) 279*58b9f456SAndroid Build Coastguard Worker __alloc_traits::destroy(__alloc(), __to_raw_pointer(__begin_++)); 280*58b9f456SAndroid Build Coastguard Worker} 281*58b9f456SAndroid Build Coastguard Worker 282*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Allocator> 283*58b9f456SAndroid Build Coastguard Workerinline 284*58b9f456SAndroid Build Coastguard Workervoid 285*58b9f456SAndroid Build Coastguard Worker__split_buffer<_Tp, _Allocator>::__destruct_at_begin(pointer __new_begin, true_type) 286*58b9f456SAndroid Build Coastguard Worker{ 287*58b9f456SAndroid Build Coastguard Worker __begin_ = __new_begin; 288*58b9f456SAndroid Build Coastguard Worker} 289*58b9f456SAndroid Build Coastguard Worker 290*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Allocator> 291*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY 292*58b9f456SAndroid Build Coastguard Workervoid 293*58b9f456SAndroid Build Coastguard Worker__split_buffer<_Tp, _Allocator>::__destruct_at_end(pointer __new_last, false_type) _NOEXCEPT 294*58b9f456SAndroid Build Coastguard Worker{ 295*58b9f456SAndroid Build Coastguard Worker while (__new_last != __end_) 296*58b9f456SAndroid Build Coastguard Worker __alloc_traits::destroy(__alloc(), __to_raw_pointer(--__end_)); 297*58b9f456SAndroid Build Coastguard Worker} 298*58b9f456SAndroid Build Coastguard Worker 299*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Allocator> 300*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY 301*58b9f456SAndroid Build Coastguard Workervoid 302*58b9f456SAndroid Build Coastguard Worker__split_buffer<_Tp, _Allocator>::__destruct_at_end(pointer __new_last, true_type) _NOEXCEPT 303*58b9f456SAndroid Build Coastguard Worker{ 304*58b9f456SAndroid Build Coastguard Worker __end_ = __new_last; 305*58b9f456SAndroid Build Coastguard Worker} 306*58b9f456SAndroid Build Coastguard Worker 307*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Allocator> 308*58b9f456SAndroid Build Coastguard Worker__split_buffer<_Tp, _Allocator>::__split_buffer(size_type __cap, size_type __start, __alloc_rr& __a) 309*58b9f456SAndroid Build Coastguard Worker : __end_cap_(nullptr, __a) 310*58b9f456SAndroid Build Coastguard Worker{ 311*58b9f456SAndroid Build Coastguard Worker __first_ = __cap != 0 ? __alloc_traits::allocate(__alloc(), __cap) : nullptr; 312*58b9f456SAndroid Build Coastguard Worker __begin_ = __end_ = __first_ + __start; 313*58b9f456SAndroid Build Coastguard Worker __end_cap() = __first_ + __cap; 314*58b9f456SAndroid Build Coastguard Worker} 315*58b9f456SAndroid Build Coastguard Worker 316*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Allocator> 317*58b9f456SAndroid Build Coastguard Workerinline 318*58b9f456SAndroid Build Coastguard Worker__split_buffer<_Tp, _Allocator>::__split_buffer() 319*58b9f456SAndroid Build Coastguard Worker _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) 320*58b9f456SAndroid Build Coastguard Worker : __first_(nullptr), __begin_(nullptr), __end_(nullptr), __end_cap_(nullptr) 321*58b9f456SAndroid Build Coastguard Worker{ 322*58b9f456SAndroid Build Coastguard Worker} 323*58b9f456SAndroid Build Coastguard Worker 324*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Allocator> 325*58b9f456SAndroid Build Coastguard Workerinline 326*58b9f456SAndroid Build Coastguard Worker__split_buffer<_Tp, _Allocator>::__split_buffer(__alloc_rr& __a) 327*58b9f456SAndroid Build Coastguard Worker : __first_(nullptr), __begin_(nullptr), __end_(nullptr), __end_cap_(nullptr, __a) 328*58b9f456SAndroid Build Coastguard Worker{ 329*58b9f456SAndroid Build Coastguard Worker} 330*58b9f456SAndroid Build Coastguard Worker 331*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Allocator> 332*58b9f456SAndroid Build Coastguard Workerinline 333*58b9f456SAndroid Build Coastguard Worker__split_buffer<_Tp, _Allocator>::__split_buffer(const __alloc_rr& __a) 334*58b9f456SAndroid Build Coastguard Worker : __first_(nullptr), __begin_(nullptr), __end_(nullptr), __end_cap_(nullptr, __a) 335*58b9f456SAndroid Build Coastguard Worker{ 336*58b9f456SAndroid Build Coastguard Worker} 337*58b9f456SAndroid Build Coastguard Worker 338*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Allocator> 339*58b9f456SAndroid Build Coastguard Worker__split_buffer<_Tp, _Allocator>::~__split_buffer() 340*58b9f456SAndroid Build Coastguard Worker{ 341*58b9f456SAndroid Build Coastguard Worker clear(); 342*58b9f456SAndroid Build Coastguard Worker if (__first_) 343*58b9f456SAndroid Build Coastguard Worker __alloc_traits::deallocate(__alloc(), __first_, capacity()); 344*58b9f456SAndroid Build Coastguard Worker} 345*58b9f456SAndroid Build Coastguard Worker 346*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_CXX03_LANG 347*58b9f456SAndroid Build Coastguard Worker 348*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Allocator> 349*58b9f456SAndroid Build Coastguard Worker__split_buffer<_Tp, _Allocator>::__split_buffer(__split_buffer&& __c) 350*58b9f456SAndroid Build Coastguard Worker _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) 351*58b9f456SAndroid Build Coastguard Worker : __first_(_VSTD::move(__c.__first_)), 352*58b9f456SAndroid Build Coastguard Worker __begin_(_VSTD::move(__c.__begin_)), 353*58b9f456SAndroid Build Coastguard Worker __end_(_VSTD::move(__c.__end_)), 354*58b9f456SAndroid Build Coastguard Worker __end_cap_(_VSTD::move(__c.__end_cap_)) 355*58b9f456SAndroid Build Coastguard Worker{ 356*58b9f456SAndroid Build Coastguard Worker __c.__first_ = nullptr; 357*58b9f456SAndroid Build Coastguard Worker __c.__begin_ = nullptr; 358*58b9f456SAndroid Build Coastguard Worker __c.__end_ = nullptr; 359*58b9f456SAndroid Build Coastguard Worker __c.__end_cap() = nullptr; 360*58b9f456SAndroid Build Coastguard Worker} 361*58b9f456SAndroid Build Coastguard Worker 362*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Allocator> 363*58b9f456SAndroid Build Coastguard Worker__split_buffer<_Tp, _Allocator>::__split_buffer(__split_buffer&& __c, const __alloc_rr& __a) 364*58b9f456SAndroid Build Coastguard Worker : __end_cap_(__second_tag(), __a) 365*58b9f456SAndroid Build Coastguard Worker{ 366*58b9f456SAndroid Build Coastguard Worker if (__a == __c.__alloc()) 367*58b9f456SAndroid Build Coastguard Worker { 368*58b9f456SAndroid Build Coastguard Worker __first_ = __c.__first_; 369*58b9f456SAndroid Build Coastguard Worker __begin_ = __c.__begin_; 370*58b9f456SAndroid Build Coastguard Worker __end_ = __c.__end_; 371*58b9f456SAndroid Build Coastguard Worker __end_cap() = __c.__end_cap(); 372*58b9f456SAndroid Build Coastguard Worker __c.__first_ = nullptr; 373*58b9f456SAndroid Build Coastguard Worker __c.__begin_ = nullptr; 374*58b9f456SAndroid Build Coastguard Worker __c.__end_ = nullptr; 375*58b9f456SAndroid Build Coastguard Worker __c.__end_cap() = nullptr; 376*58b9f456SAndroid Build Coastguard Worker } 377*58b9f456SAndroid Build Coastguard Worker else 378*58b9f456SAndroid Build Coastguard Worker { 379*58b9f456SAndroid Build Coastguard Worker size_type __cap = __c.size(); 380*58b9f456SAndroid Build Coastguard Worker __first_ = __alloc_traits::allocate(__alloc(), __cap); 381*58b9f456SAndroid Build Coastguard Worker __begin_ = __end_ = __first_; 382*58b9f456SAndroid Build Coastguard Worker __end_cap() = __first_ + __cap; 383*58b9f456SAndroid Build Coastguard Worker typedef move_iterator<iterator> _Ip; 384*58b9f456SAndroid Build Coastguard Worker __construct_at_end(_Ip(__c.begin()), _Ip(__c.end())); 385*58b9f456SAndroid Build Coastguard Worker } 386*58b9f456SAndroid Build Coastguard Worker} 387*58b9f456SAndroid Build Coastguard Worker 388*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Allocator> 389*58b9f456SAndroid Build Coastguard Worker__split_buffer<_Tp, _Allocator>& 390*58b9f456SAndroid Build Coastguard Worker__split_buffer<_Tp, _Allocator>::operator=(__split_buffer&& __c) 391*58b9f456SAndroid Build Coastguard Worker _NOEXCEPT_((__alloc_traits::propagate_on_container_move_assignment::value && 392*58b9f456SAndroid Build Coastguard Worker is_nothrow_move_assignable<allocator_type>::value) || 393*58b9f456SAndroid Build Coastguard Worker !__alloc_traits::propagate_on_container_move_assignment::value) 394*58b9f456SAndroid Build Coastguard Worker{ 395*58b9f456SAndroid Build Coastguard Worker clear(); 396*58b9f456SAndroid Build Coastguard Worker shrink_to_fit(); 397*58b9f456SAndroid Build Coastguard Worker __first_ = __c.__first_; 398*58b9f456SAndroid Build Coastguard Worker __begin_ = __c.__begin_; 399*58b9f456SAndroid Build Coastguard Worker __end_ = __c.__end_; 400*58b9f456SAndroid Build Coastguard Worker __end_cap() = __c.__end_cap(); 401*58b9f456SAndroid Build Coastguard Worker __move_assign_alloc(__c, 402*58b9f456SAndroid Build Coastguard Worker integral_constant<bool, 403*58b9f456SAndroid Build Coastguard Worker __alloc_traits::propagate_on_container_move_assignment::value>()); 404*58b9f456SAndroid Build Coastguard Worker __c.__first_ = __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr; 405*58b9f456SAndroid Build Coastguard Worker return *this; 406*58b9f456SAndroid Build Coastguard Worker} 407*58b9f456SAndroid Build Coastguard Worker 408*58b9f456SAndroid Build Coastguard Worker#endif // _LIBCPP_CXX03_LANG 409*58b9f456SAndroid Build Coastguard Worker 410*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Allocator> 411*58b9f456SAndroid Build Coastguard Workervoid 412*58b9f456SAndroid Build Coastguard Worker__split_buffer<_Tp, _Allocator>::swap(__split_buffer& __x) 413*58b9f456SAndroid Build Coastguard Worker _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value|| 414*58b9f456SAndroid Build Coastguard Worker __is_nothrow_swappable<__alloc_rr>::value) 415*58b9f456SAndroid Build Coastguard Worker{ 416*58b9f456SAndroid Build Coastguard Worker _VSTD::swap(__first_, __x.__first_); 417*58b9f456SAndroid Build Coastguard Worker _VSTD::swap(__begin_, __x.__begin_); 418*58b9f456SAndroid Build Coastguard Worker _VSTD::swap(__end_, __x.__end_); 419*58b9f456SAndroid Build Coastguard Worker _VSTD::swap(__end_cap(), __x.__end_cap()); 420*58b9f456SAndroid Build Coastguard Worker __swap_allocator(__alloc(), __x.__alloc()); 421*58b9f456SAndroid Build Coastguard Worker} 422*58b9f456SAndroid Build Coastguard Worker 423*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Allocator> 424*58b9f456SAndroid Build Coastguard Workervoid 425*58b9f456SAndroid Build Coastguard Worker__split_buffer<_Tp, _Allocator>::reserve(size_type __n) 426*58b9f456SAndroid Build Coastguard Worker{ 427*58b9f456SAndroid Build Coastguard Worker if (__n < capacity()) 428*58b9f456SAndroid Build Coastguard Worker { 429*58b9f456SAndroid Build Coastguard Worker __split_buffer<value_type, __alloc_rr&> __t(__n, 0, __alloc()); 430*58b9f456SAndroid Build Coastguard Worker __t.__construct_at_end(move_iterator<pointer>(__begin_), 431*58b9f456SAndroid Build Coastguard Worker move_iterator<pointer>(__end_)); 432*58b9f456SAndroid Build Coastguard Worker _VSTD::swap(__first_, __t.__first_); 433*58b9f456SAndroid Build Coastguard Worker _VSTD::swap(__begin_, __t.__begin_); 434*58b9f456SAndroid Build Coastguard Worker _VSTD::swap(__end_, __t.__end_); 435*58b9f456SAndroid Build Coastguard Worker _VSTD::swap(__end_cap(), __t.__end_cap()); 436*58b9f456SAndroid Build Coastguard Worker } 437*58b9f456SAndroid Build Coastguard Worker} 438*58b9f456SAndroid Build Coastguard Worker 439*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Allocator> 440*58b9f456SAndroid Build Coastguard Workervoid 441*58b9f456SAndroid Build Coastguard Worker__split_buffer<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT 442*58b9f456SAndroid Build Coastguard Worker{ 443*58b9f456SAndroid Build Coastguard Worker if (capacity() > size()) 444*58b9f456SAndroid Build Coastguard Worker { 445*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_EXCEPTIONS 446*58b9f456SAndroid Build Coastguard Worker try 447*58b9f456SAndroid Build Coastguard Worker { 448*58b9f456SAndroid Build Coastguard Worker#endif // _LIBCPP_NO_EXCEPTIONS 449*58b9f456SAndroid Build Coastguard Worker __split_buffer<value_type, __alloc_rr&> __t(size(), 0, __alloc()); 450*58b9f456SAndroid Build Coastguard Worker __t.__construct_at_end(move_iterator<pointer>(__begin_), 451*58b9f456SAndroid Build Coastguard Worker move_iterator<pointer>(__end_)); 452*58b9f456SAndroid Build Coastguard Worker __t.__end_ = __t.__begin_ + (__end_ - __begin_); 453*58b9f456SAndroid Build Coastguard Worker _VSTD::swap(__first_, __t.__first_); 454*58b9f456SAndroid Build Coastguard Worker _VSTD::swap(__begin_, __t.__begin_); 455*58b9f456SAndroid Build Coastguard Worker _VSTD::swap(__end_, __t.__end_); 456*58b9f456SAndroid Build Coastguard Worker _VSTD::swap(__end_cap(), __t.__end_cap()); 457*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_EXCEPTIONS 458*58b9f456SAndroid Build Coastguard Worker } 459*58b9f456SAndroid Build Coastguard Worker catch (...) 460*58b9f456SAndroid Build Coastguard Worker { 461*58b9f456SAndroid Build Coastguard Worker } 462*58b9f456SAndroid Build Coastguard Worker#endif // _LIBCPP_NO_EXCEPTIONS 463*58b9f456SAndroid Build Coastguard Worker } 464*58b9f456SAndroid Build Coastguard Worker} 465*58b9f456SAndroid Build Coastguard Worker 466*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Allocator> 467*58b9f456SAndroid Build Coastguard Workervoid 468*58b9f456SAndroid Build Coastguard Worker__split_buffer<_Tp, _Allocator>::push_front(const_reference __x) 469*58b9f456SAndroid Build Coastguard Worker{ 470*58b9f456SAndroid Build Coastguard Worker if (__begin_ == __first_) 471*58b9f456SAndroid Build Coastguard Worker { 472*58b9f456SAndroid Build Coastguard Worker if (__end_ < __end_cap()) 473*58b9f456SAndroid Build Coastguard Worker { 474*58b9f456SAndroid Build Coastguard Worker difference_type __d = __end_cap() - __end_; 475*58b9f456SAndroid Build Coastguard Worker __d = (__d + 1) / 2; 476*58b9f456SAndroid Build Coastguard Worker __begin_ = _VSTD::move_backward(__begin_, __end_, __end_ + __d); 477*58b9f456SAndroid Build Coastguard Worker __end_ += __d; 478*58b9f456SAndroid Build Coastguard Worker } 479*58b9f456SAndroid Build Coastguard Worker else 480*58b9f456SAndroid Build Coastguard Worker { 481*58b9f456SAndroid Build Coastguard Worker size_type __c = max<size_type>(2 * static_cast<size_t>(__end_cap() - __first_), 1); 482*58b9f456SAndroid Build Coastguard Worker __split_buffer<value_type, __alloc_rr&> __t(__c, (__c + 3) / 4, __alloc()); 483*58b9f456SAndroid Build Coastguard Worker __t.__construct_at_end(move_iterator<pointer>(__begin_), 484*58b9f456SAndroid Build Coastguard Worker move_iterator<pointer>(__end_)); 485*58b9f456SAndroid Build Coastguard Worker _VSTD::swap(__first_, __t.__first_); 486*58b9f456SAndroid Build Coastguard Worker _VSTD::swap(__begin_, __t.__begin_); 487*58b9f456SAndroid Build Coastguard Worker _VSTD::swap(__end_, __t.__end_); 488*58b9f456SAndroid Build Coastguard Worker _VSTD::swap(__end_cap(), __t.__end_cap()); 489*58b9f456SAndroid Build Coastguard Worker } 490*58b9f456SAndroid Build Coastguard Worker } 491*58b9f456SAndroid Build Coastguard Worker __alloc_traits::construct(__alloc(), _VSTD::__to_raw_pointer(__begin_-1), __x); 492*58b9f456SAndroid Build Coastguard Worker --__begin_; 493*58b9f456SAndroid Build Coastguard Worker} 494*58b9f456SAndroid Build Coastguard Worker 495*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_CXX03_LANG 496*58b9f456SAndroid Build Coastguard Worker 497*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Allocator> 498*58b9f456SAndroid Build Coastguard Workervoid 499*58b9f456SAndroid Build Coastguard Worker__split_buffer<_Tp, _Allocator>::push_front(value_type&& __x) 500*58b9f456SAndroid Build Coastguard Worker{ 501*58b9f456SAndroid Build Coastguard Worker if (__begin_ == __first_) 502*58b9f456SAndroid Build Coastguard Worker { 503*58b9f456SAndroid Build Coastguard Worker if (__end_ < __end_cap()) 504*58b9f456SAndroid Build Coastguard Worker { 505*58b9f456SAndroid Build Coastguard Worker difference_type __d = __end_cap() - __end_; 506*58b9f456SAndroid Build Coastguard Worker __d = (__d + 1) / 2; 507*58b9f456SAndroid Build Coastguard Worker __begin_ = _VSTD::move_backward(__begin_, __end_, __end_ + __d); 508*58b9f456SAndroid Build Coastguard Worker __end_ += __d; 509*58b9f456SAndroid Build Coastguard Worker } 510*58b9f456SAndroid Build Coastguard Worker else 511*58b9f456SAndroid Build Coastguard Worker { 512*58b9f456SAndroid Build Coastguard Worker size_type __c = max<size_type>(2 * static_cast<size_t>(__end_cap() - __first_), 1); 513*58b9f456SAndroid Build Coastguard Worker __split_buffer<value_type, __alloc_rr&> __t(__c, (__c + 3) / 4, __alloc()); 514*58b9f456SAndroid Build Coastguard Worker __t.__construct_at_end(move_iterator<pointer>(__begin_), 515*58b9f456SAndroid Build Coastguard Worker move_iterator<pointer>(__end_)); 516*58b9f456SAndroid Build Coastguard Worker _VSTD::swap(__first_, __t.__first_); 517*58b9f456SAndroid Build Coastguard Worker _VSTD::swap(__begin_, __t.__begin_); 518*58b9f456SAndroid Build Coastguard Worker _VSTD::swap(__end_, __t.__end_); 519*58b9f456SAndroid Build Coastguard Worker _VSTD::swap(__end_cap(), __t.__end_cap()); 520*58b9f456SAndroid Build Coastguard Worker } 521*58b9f456SAndroid Build Coastguard Worker } 522*58b9f456SAndroid Build Coastguard Worker __alloc_traits::construct(__alloc(), _VSTD::__to_raw_pointer(__begin_-1), 523*58b9f456SAndroid Build Coastguard Worker _VSTD::move(__x)); 524*58b9f456SAndroid Build Coastguard Worker --__begin_; 525*58b9f456SAndroid Build Coastguard Worker} 526*58b9f456SAndroid Build Coastguard Worker 527*58b9f456SAndroid Build Coastguard Worker#endif // _LIBCPP_CXX03_LANG 528*58b9f456SAndroid Build Coastguard Worker 529*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Allocator> 530*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY 531*58b9f456SAndroid Build Coastguard Workervoid 532*58b9f456SAndroid Build Coastguard Worker__split_buffer<_Tp, _Allocator>::push_back(const_reference __x) 533*58b9f456SAndroid Build Coastguard Worker{ 534*58b9f456SAndroid Build Coastguard Worker if (__end_ == __end_cap()) 535*58b9f456SAndroid Build Coastguard Worker { 536*58b9f456SAndroid Build Coastguard Worker if (__begin_ > __first_) 537*58b9f456SAndroid Build Coastguard Worker { 538*58b9f456SAndroid Build Coastguard Worker difference_type __d = __begin_ - __first_; 539*58b9f456SAndroid Build Coastguard Worker __d = (__d + 1) / 2; 540*58b9f456SAndroid Build Coastguard Worker __end_ = _VSTD::move(__begin_, __end_, __begin_ - __d); 541*58b9f456SAndroid Build Coastguard Worker __begin_ -= __d; 542*58b9f456SAndroid Build Coastguard Worker } 543*58b9f456SAndroid Build Coastguard Worker else 544*58b9f456SAndroid Build Coastguard Worker { 545*58b9f456SAndroid Build Coastguard Worker size_type __c = max<size_type>(2 * static_cast<size_t>(__end_cap() - __first_), 1); 546*58b9f456SAndroid Build Coastguard Worker __split_buffer<value_type, __alloc_rr&> __t(__c, __c / 4, __alloc()); 547*58b9f456SAndroid Build Coastguard Worker __t.__construct_at_end(move_iterator<pointer>(__begin_), 548*58b9f456SAndroid Build Coastguard Worker move_iterator<pointer>(__end_)); 549*58b9f456SAndroid Build Coastguard Worker _VSTD::swap(__first_, __t.__first_); 550*58b9f456SAndroid Build Coastguard Worker _VSTD::swap(__begin_, __t.__begin_); 551*58b9f456SAndroid Build Coastguard Worker _VSTD::swap(__end_, __t.__end_); 552*58b9f456SAndroid Build Coastguard Worker _VSTD::swap(__end_cap(), __t.__end_cap()); 553*58b9f456SAndroid Build Coastguard Worker } 554*58b9f456SAndroid Build Coastguard Worker } 555*58b9f456SAndroid Build Coastguard Worker __alloc_traits::construct(__alloc(), _VSTD::__to_raw_pointer(__end_), __x); 556*58b9f456SAndroid Build Coastguard Worker ++__end_; 557*58b9f456SAndroid Build Coastguard Worker} 558*58b9f456SAndroid Build Coastguard Worker 559*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_CXX03_LANG 560*58b9f456SAndroid Build Coastguard Worker 561*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Allocator> 562*58b9f456SAndroid Build Coastguard Workervoid 563*58b9f456SAndroid Build Coastguard Worker__split_buffer<_Tp, _Allocator>::push_back(value_type&& __x) 564*58b9f456SAndroid Build Coastguard Worker{ 565*58b9f456SAndroid Build Coastguard Worker if (__end_ == __end_cap()) 566*58b9f456SAndroid Build Coastguard Worker { 567*58b9f456SAndroid Build Coastguard Worker if (__begin_ > __first_) 568*58b9f456SAndroid Build Coastguard Worker { 569*58b9f456SAndroid Build Coastguard Worker difference_type __d = __begin_ - __first_; 570*58b9f456SAndroid Build Coastguard Worker __d = (__d + 1) / 2; 571*58b9f456SAndroid Build Coastguard Worker __end_ = _VSTD::move(__begin_, __end_, __begin_ - __d); 572*58b9f456SAndroid Build Coastguard Worker __begin_ -= __d; 573*58b9f456SAndroid Build Coastguard Worker } 574*58b9f456SAndroid Build Coastguard Worker else 575*58b9f456SAndroid Build Coastguard Worker { 576*58b9f456SAndroid Build Coastguard Worker size_type __c = max<size_type>(2 * static_cast<size_t>(__end_cap() - __first_), 1); 577*58b9f456SAndroid Build Coastguard Worker __split_buffer<value_type, __alloc_rr&> __t(__c, __c / 4, __alloc()); 578*58b9f456SAndroid Build Coastguard Worker __t.__construct_at_end(move_iterator<pointer>(__begin_), 579*58b9f456SAndroid Build Coastguard Worker move_iterator<pointer>(__end_)); 580*58b9f456SAndroid Build Coastguard Worker _VSTD::swap(__first_, __t.__first_); 581*58b9f456SAndroid Build Coastguard Worker _VSTD::swap(__begin_, __t.__begin_); 582*58b9f456SAndroid Build Coastguard Worker _VSTD::swap(__end_, __t.__end_); 583*58b9f456SAndroid Build Coastguard Worker _VSTD::swap(__end_cap(), __t.__end_cap()); 584*58b9f456SAndroid Build Coastguard Worker } 585*58b9f456SAndroid Build Coastguard Worker } 586*58b9f456SAndroid Build Coastguard Worker __alloc_traits::construct(__alloc(), _VSTD::__to_raw_pointer(__end_), 587*58b9f456SAndroid Build Coastguard Worker _VSTD::move(__x)); 588*58b9f456SAndroid Build Coastguard Worker ++__end_; 589*58b9f456SAndroid Build Coastguard Worker} 590*58b9f456SAndroid Build Coastguard Worker 591*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Allocator> 592*58b9f456SAndroid Build Coastguard Workertemplate <class... _Args> 593*58b9f456SAndroid Build Coastguard Workervoid 594*58b9f456SAndroid Build Coastguard Worker__split_buffer<_Tp, _Allocator>::emplace_back(_Args&&... __args) 595*58b9f456SAndroid Build Coastguard Worker{ 596*58b9f456SAndroid Build Coastguard Worker if (__end_ == __end_cap()) 597*58b9f456SAndroid Build Coastguard Worker { 598*58b9f456SAndroid Build Coastguard Worker if (__begin_ > __first_) 599*58b9f456SAndroid Build Coastguard Worker { 600*58b9f456SAndroid Build Coastguard Worker difference_type __d = __begin_ - __first_; 601*58b9f456SAndroid Build Coastguard Worker __d = (__d + 1) / 2; 602*58b9f456SAndroid Build Coastguard Worker __end_ = _VSTD::move(__begin_, __end_, __begin_ - __d); 603*58b9f456SAndroid Build Coastguard Worker __begin_ -= __d; 604*58b9f456SAndroid Build Coastguard Worker } 605*58b9f456SAndroid Build Coastguard Worker else 606*58b9f456SAndroid Build Coastguard Worker { 607*58b9f456SAndroid Build Coastguard Worker size_type __c = max<size_type>(2 * static_cast<size_t>(__end_cap() - __first_), 1); 608*58b9f456SAndroid Build Coastguard Worker __split_buffer<value_type, __alloc_rr&> __t(__c, __c / 4, __alloc()); 609*58b9f456SAndroid Build Coastguard Worker __t.__construct_at_end(move_iterator<pointer>(__begin_), 610*58b9f456SAndroid Build Coastguard Worker move_iterator<pointer>(__end_)); 611*58b9f456SAndroid Build Coastguard Worker _VSTD::swap(__first_, __t.__first_); 612*58b9f456SAndroid Build Coastguard Worker _VSTD::swap(__begin_, __t.__begin_); 613*58b9f456SAndroid Build Coastguard Worker _VSTD::swap(__end_, __t.__end_); 614*58b9f456SAndroid Build Coastguard Worker _VSTD::swap(__end_cap(), __t.__end_cap()); 615*58b9f456SAndroid Build Coastguard Worker } 616*58b9f456SAndroid Build Coastguard Worker } 617*58b9f456SAndroid Build Coastguard Worker __alloc_traits::construct(__alloc(), _VSTD::__to_raw_pointer(__end_), 618*58b9f456SAndroid Build Coastguard Worker _VSTD::forward<_Args>(__args)...); 619*58b9f456SAndroid Build Coastguard Worker ++__end_; 620*58b9f456SAndroid Build Coastguard Worker} 621*58b9f456SAndroid Build Coastguard Worker 622*58b9f456SAndroid Build Coastguard Worker#endif // _LIBCPP_CXX03_LANG 623*58b9f456SAndroid Build Coastguard Worker 624*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Allocator> 625*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY 626*58b9f456SAndroid Build Coastguard Workervoid 627*58b9f456SAndroid Build Coastguard Workerswap(__split_buffer<_Tp, _Allocator>& __x, __split_buffer<_Tp, _Allocator>& __y) 628*58b9f456SAndroid Build Coastguard Worker _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) 629*58b9f456SAndroid Build Coastguard Worker{ 630*58b9f456SAndroid Build Coastguard Worker __x.swap(__y); 631*58b9f456SAndroid Build Coastguard Worker} 632*58b9f456SAndroid Build Coastguard Worker 633*58b9f456SAndroid Build Coastguard Worker_LIBCPP_END_NAMESPACE_STD 634*58b9f456SAndroid Build Coastguard Worker 635*58b9f456SAndroid Build Coastguard Worker_LIBCPP_POP_MACROS 636*58b9f456SAndroid Build Coastguard Worker 637*58b9f456SAndroid Build Coastguard Worker#endif // _LIBCPP_SPLIT_BUFFER 638