diff options
author | Alon Zakai <alonzakai@gmail.com> | 2011-09-24 19:06:33 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2011-09-24 19:06:33 -0700 |
commit | 1ea039eea38dad37c5b0c836cf98829bad6013ce (patch) | |
tree | 6d851de99c00b4aa1c45624df570b5cb7f89fed5 /system/include/libcxx/vector | |
parent | dd0230c9cf09a7b19712a4acefe0ae27ea40ea85 (diff) |
include libcxx
Diffstat (limited to 'system/include/libcxx/vector')
-rw-r--r-- | system/include/libcxx/vector | 3135 |
1 files changed, 3135 insertions, 0 deletions
diff --git a/system/include/libcxx/vector b/system/include/libcxx/vector new file mode 100644 index 00000000..b334074d --- /dev/null +++ b/system/include/libcxx/vector @@ -0,0 +1,3135 @@ +// -*- C++ -*- +//===------------------------------ vector --------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_VECTOR +#define _LIBCPP_VECTOR + +/* + vector synopsis + +namespace std +{ + +template <class T, class Allocator = allocator<T> > +class vector +{ +public: + typedef T value_type; + typedef Allocator allocator_type; + typedef typename allocator_type::reference reference; + typedef typename allocator_type::const_reference const_reference; + typedef implementation-defined iterator; + typedef implementation-defined const_iterator; + typedef typename allocator_type::size_type size_type; + typedef typename allocator_type::difference_type difference_type; + typedef typename allocator_type::pointer pointer; + typedef typename allocator_type::const_pointer const_pointer; + typedef std::reverse_iterator<iterator> reverse_iterator; + typedef std::reverse_iterator<const_iterator> const_reverse_iterator; + + vector() + noexcept(is_nothrow_default_constructible<allocator_type>::value); + explicit vector(const allocator_type&); + explicit vector(size_type n); + vector(size_type n, const value_type& value, const allocator_type& = allocator_type()); + template <class InputIterator> + vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type()); + vector(const vector& x); + vector(vector&& x) + noexcept(is_nothrow_move_constructible<allocator_type>::value); + vector(initializer_list<value_type> il); + vector(initializer_list<value_type> il, const allocator_type& a); + ~vector(); + vector& operator=(const vector& x); + vector& operator=(vector&& x) + noexcept( + allocator_type::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable<allocator_type>::value); + vector& operator=(initializer_list<value_type> il); + template <class InputIterator> + void assign(InputIterator first, InputIterator last); + void assign(size_type n, const value_type& u); + void assign(initializer_list<value_type> il); + + allocator_type get_allocator() const noexcept; + + iterator begin() noexcept; + const_iterator begin() const noexcept; + iterator end() noexcept; + const_iterator end() const noexcept; + + reverse_iterator rbegin() noexcept; + const_reverse_iterator rbegin() const noexcept; + reverse_iterator rend() noexcept; + const_reverse_iterator rend() const noexcept; + + const_iterator cbegin() const noexcept; + const_iterator cend() const noexcept; + const_reverse_iterator crbegin() const noexcept; + const_reverse_iterator crend() const noexcept; + + size_type size() const noexcept; + size_type max_size() const noexcept; + size_type capacity() const noexcept; + bool empty() const noexcept; + void reserve(size_type n); + void shrink_to_fit() noexcept; + + reference operator[](size_type n); + const_reference operator[](size_type n) const; + reference at(size_type n); + const_reference at(size_type n) const; + + reference front(); + const_reference front() const; + reference back(); + const_reference back() const; + + value_type* data() noexcept; + const value_type* data() const noexcept; + + void push_back(const value_type& x); + void push_back(value_type&& x); + template <class... Args> + void emplace_back(Args&&... args); + void pop_back(); + + template <class... Args> iterator emplace(const_iterator position, Args&&... args); + iterator insert(const_iterator position, const value_type& x); + iterator insert(const_iterator position, value_type&& x); + iterator insert(const_iterator position, size_type n, const value_type& x); + template <class InputIterator> + iterator insert(const_iterator position, InputIterator first, InputIterator last); + iterator insert(const_iterator position, initializer_list<value_type> il); + + iterator erase(const_iterator position); + iterator erase(const_iterator first, const_iterator last); + + void clear() noexcept; + + void resize(size_type sz); + void resize(size_type sz, const value_type& c); + + void swap(vector&) + noexcept(!allocator_type::propagate_on_container_swap::value || + __is_nothrow_swappable<allocator_type>::value); + + bool __invariants() const; +}; + +template <class Allocator = allocator<T> > +class vector<bool, Allocator> +{ +public: + typedef bool value_type; + typedef Allocator allocator_type; + typedef implementation-defined iterator; + typedef implementation-defined const_iterator; + typedef typename allocator_type::size_type size_type; + typedef typename allocator_type::difference_type difference_type; + typedef iterator pointer; + typedef const_iterator const_pointer; + typedef std::reverse_iterator<iterator> reverse_iterator; + typedef std::reverse_iterator<const_iterator> const_reverse_iterator; + + class reference + { + public: + reference(const reference&) noexcept; + operator bool() const noexcept; + reference& operator=(const bool x) noexcept; + reference& operator=(const reference& x) noexcept; + iterator operator&() const noexcept; + void flip() noexcept; + }; + + class const_reference + { + public: + const_reference(const reference&) noexcept; + operator bool() const noexcept; + const_iterator operator&() const noexcept; + }; + + vector() + noexcept(is_nothrow_default_constructible<allocator_type>::value); + explicit vector(const allocator_type&); + explicit vector(size_type n, const value_type& value = value_type(), const allocator_type& = allocator_type()); + template <class InputIterator> + vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type()); + vector(const vector& x); + vector(vector&& x) + noexcept(is_nothrow_move_constructible<allocator_type>::value); + vector(initializer_list<value_type> il); + vector(initializer_list<value_type> il, const allocator_type& a); + ~vector(); + vector& operator=(const vector& x); + vector& operator=(vector&& x) + noexcept( + allocator_type::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable<allocator_type>::value); + vector& operator=(initializer_list<value_type> il); + template <class InputIterator> + void assign(InputIterator first, InputIterator last); + void assign(size_type n, const value_type& u); + void assign(initializer_list<value_type> il); + + allocator_type get_allocator() const noexcept; + + iterator begin() noexcept; + const_iterator begin() const noexcept; + iterator end() noexcept; + const_iterator end() const noexcept; + + reverse_iterator rbegin() noexcept; + const_reverse_iterator rbegin() const noexcept; + reverse_iterator rend() noexcept; + const_reverse_iterator rend() const noexcept; + + const_iterator cbegin() const noexcept; + const_iterator cend() const noexcept; + const_reverse_iterator crbegin() const noexcept; + const_reverse_iterator crend() const noexcept; + + size_type size() const noexcept; + size_type max_size() const noexcept; + size_type capacity() const noexcept; + bool empty() const noexcept; + void reserve(size_type n); + void shrink_to_fit() noexcept; + + reference operator[](size_type n); + const_reference operator[](size_type n) const; + reference at(size_type n); + const_reference at(size_type n) const; + + reference front(); + const_reference front() const; + reference back(); + const_reference back() const; + + void push_back(const value_type& x); + void pop_back(); + + iterator insert(const_iterator position, const value_type& x); + iterator insert(const_iterator position, size_type n, const value_type& x); + template <class InputIterator> + iterator insert(const_iterator position, InputIterator first, InputIterator last); + iterator insert(const_iterator position, initializer_list<value_type> il); + + iterator erase(const_iterator position); + iterator erase(const_iterator first, const_iterator last); + + void clear() noexcept; + + void resize(size_type sz); + void resize(size_type sz, value_type x); + + void swap(vector&) + noexcept(!allocator_type::propagate_on_container_swap::value || + __is_nothrow_swappable<allocator_type>::value); + void flip() noexcept; + + bool __invariants() const; +}; + +template <class Allocator> struct hash<std::vector<bool, Allocator>>; + +template <class T, class Allocator> bool operator==(const vector<T,Allocator>& x, const vector<T,Allocator>& y); +template <class T, class Allocator> bool operator< (const vector<T,Allocator>& x, const vector<T,Allocator>& y); +template <class T, class Allocator> bool operator!=(const vector<T,Allocator>& x, const vector<T,Allocator>& y); +template <class T, class Allocator> bool operator> (const vector<T,Allocator>& x, const vector<T,Allocator>& y); +template <class T, class Allocator> bool operator>=(const vector<T,Allocator>& x, const vector<T,Allocator>& y); +template <class T, class Allocator> bool operator<=(const vector<T,Allocator>& x, const vector<T,Allocator>& y); + +template <class T, class Allocator> +void swap(vector<T,Allocator>& x, vector<T,Allocator>& y) + noexcept(noexcept(x.swap(y))); + +} // std + +*/ + +#include <__config> +#include <__bit_reference> +#include <type_traits> +#include <climits> +#include <limits> +#include <initializer_list> +#include <memory> +#include <stdexcept> +#include <algorithm> +#include <cstring> +#include <__split_buffer> +#include <__functional_base> + +#pragma GCC system_header + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <bool> +class __vector_base_common +{ +protected: + _LIBCPP_ALWAYS_INLINE __vector_base_common() {} + void __throw_length_error() const; + void __throw_out_of_range() const; +}; + +template <bool __b> +void +__vector_base_common<__b>::__throw_length_error() const +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + throw length_error("vector"); +#else + assert(!"vector length_error"); +#endif +} + +template <bool __b> +void +__vector_base_common<__b>::__throw_out_of_range() const +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + throw out_of_range("vector"); +#else + assert(!"vector out_of_range"); +#endif +} + +extern template class __vector_base_common<true>; + +template <class _Tp, class _Allocator> +class __vector_base + : protected __vector_base_common<true> +{ +protected: + typedef _Tp value_type; + typedef _Allocator allocator_type; + typedef allocator_traits<allocator_type> __alloc_traits; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef typename __alloc_traits::size_type size_type; + typedef typename __alloc_traits::difference_type difference_type; + typedef typename __alloc_traits::pointer pointer; + typedef typename __alloc_traits::const_pointer const_pointer; + typedef pointer iterator; + typedef const_pointer const_iterator; + + pointer __begin_; + pointer __end_; + __compressed_pair<pointer, allocator_type> __end_cap_; + + _LIBCPP_INLINE_VISIBILITY + allocator_type& __alloc() _NOEXCEPT + {return __end_cap_.second();} + _LIBCPP_INLINE_VISIBILITY + const allocator_type& __alloc() const _NOEXCEPT + {return __end_cap_.second();} + _LIBCPP_INLINE_VISIBILITY + pointer& __end_cap() _NOEXCEPT + {return __end_cap_.first();} + _LIBCPP_INLINE_VISIBILITY + const pointer& __end_cap() const _NOEXCEPT + {return __end_cap_.first();} + + _LIBCPP_INLINE_VISIBILITY + __vector_base() + _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value); + _LIBCPP_INLINE_VISIBILITY __vector_base(const allocator_type& __a); + ~__vector_base(); + + _LIBCPP_INLINE_VISIBILITY + void clear() _NOEXCEPT {__destruct_at_end(__begin_);} + _LIBCPP_INLINE_VISIBILITY + size_type capacity() const _NOEXCEPT + {return static_cast<size_type>(__end_cap() - __begin_);} + + _LIBCPP_INLINE_VISIBILITY + void __destruct_at_end(const_pointer __new_last) _NOEXCEPT + {__destruct_at_end(__new_last, is_trivially_destructible<value_type>());} + _LIBCPP_INLINE_VISIBILITY + void __destruct_at_end(const_pointer __new_last, false_type) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + void __destruct_at_end(const_pointer __new_last, true_type) _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const __vector_base& __c) + {__copy_assign_alloc(__c, integral_constant<bool, + __alloc_traits::propagate_on_container_copy_assignment::value>());} + + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__vector_base& __c) + _NOEXCEPT_( + !__alloc_traits::propagate_on_container_move_assignment::value || + is_nothrow_move_assignable<allocator_type>::value) + {__move_assign_alloc(__c, integral_constant<bool, + __alloc_traits::propagate_on_container_move_assignment::value>());} + + _LIBCPP_INLINE_VISIBILITY + static void __swap_alloc(allocator_type& __x, allocator_type& __y) + _NOEXCEPT_( + !__alloc_traits::propagate_on_container_swap::value || + __is_nothrow_swappable<allocator_type>::value) + {__swap_alloc(__x, __y, integral_constant<bool, + __alloc_traits::propagate_on_container_swap::value>());} +private: + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const __vector_base& __c, true_type) + { + if (__alloc() != __c.__alloc()) + { + clear(); + __alloc_traits::deallocate(__alloc(), __begin_, capacity()); + __begin_ = __end_ = __end_cap() = nullptr; + } + __alloc() = __c.__alloc(); + } + + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const __vector_base& __c, false_type) + {} + + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__vector_base& __c, true_type) + _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) + { + __alloc() = _VSTD::move(__c.__alloc()); + } + + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__vector_base& __c, false_type) + _NOEXCEPT + {} + + _LIBCPP_INLINE_VISIBILITY + static void __swap_alloc(allocator_type& __x, allocator_type& __y, true_type) + _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) + { + using _VSTD::swap; + swap(__x, __y); + } + _LIBCPP_INLINE_VISIBILITY + static void __swap_alloc(allocator_type& __x, allocator_type& __y, false_type) + _NOEXCEPT + {} +}; + +template <class _Tp, class _Allocator> +_LIBCPP_INLINE_VISIBILITY inline +void +__vector_base<_Tp, _Allocator>::__destruct_at_end(const_pointer __new_last, false_type) _NOEXCEPT +{ + while (__new_last < __end_) + __alloc_traits::destroy(__alloc(), const_cast<pointer>(--__end_)); +} + +template <class _Tp, class _Allocator> +_LIBCPP_INLINE_VISIBILITY inline +void +__vector_base<_Tp, _Allocator>::__destruct_at_end(const_pointer __new_last, true_type) _NOEXCEPT +{ + __end_ = const_cast<pointer>(__new_last); +} + +template <class _Tp, class _Allocator> +_LIBCPP_INLINE_VISIBILITY inline +__vector_base<_Tp, _Allocator>::__vector_base() + _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) + : __begin_(0), + __end_(0), + __end_cap_(0) +{ +} + +template <class _Tp, class _Allocator> +_LIBCPP_INLINE_VISIBILITY inline +__vector_base<_Tp, _Allocator>::__vector_base(const allocator_type& __a) + : __begin_(0), + __end_(0), + __end_cap_(0, __a) +{ +} + +template <class _Tp, class _Allocator> +__vector_base<_Tp, _Allocator>::~__vector_base() +{ + if (__begin_ != 0) + { + clear(); + __alloc_traits::deallocate(__alloc(), __begin_, capacity()); + } +} + +template <class _Tp, class _Allocator = allocator<_Tp> > +class _LIBCPP_VISIBLE vector + : private __vector_base<_Tp, _Allocator> +{ +private: + typedef __vector_base<_Tp, _Allocator> __base; +public: + typedef vector __self; + typedef _Tp value_type; + typedef _Allocator allocator_type; + typedef typename __base::__alloc_traits __alloc_traits; + typedef typename __base::reference reference; + typedef typename __base::const_reference const_reference; + typedef typename __base::size_type size_type; + typedef typename __base::difference_type difference_type; + typedef typename __base::pointer pointer; + typedef typename __base::const_pointer const_pointer; + typedef __wrap_iter<pointer> iterator; + typedef __wrap_iter<const_pointer> const_iterator; + typedef _VSTD::reverse_iterator<iterator> reverse_iterator; + typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; + + _LIBCPP_INLINE_VISIBILITY + vector() + _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + } + _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a) + : __base(__a) + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + } + explicit vector(size_type __n); + vector(size_type __n, const_reference __x); + vector(size_type __n, const_reference __x, const allocator_type& __a); + template <class _InputIterator> + vector(_InputIterator __first, _InputIterator __last, + typename enable_if<__is_input_iterator <_InputIterator>::value && + !__is_forward_iterator<_InputIterator>::value>::type* = 0); + template <class _InputIterator> + vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, + typename enable_if<__is_input_iterator <_InputIterator>::value && + !__is_forward_iterator<_InputIterator>::value>::type* = 0); + template <class _ForwardIterator> + vector(_ForwardIterator __first, _ForwardIterator __last, + typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0); + template <class _ForwardIterator> + vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, + typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0); +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + _LIBCPP_INLINE_VISIBILITY + vector(initializer_list<value_type> __il); + _LIBCPP_INLINE_VISIBILITY + vector(initializer_list<value_type> __il, const allocator_type& __a); +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_INLINE_VISIBILITY + ~vector() + { + __get_db()->__erase_c(this); + } +#endif + + vector(const vector& __x); + vector(const vector& __x, const allocator_type& __a); + _LIBCPP_INLINE_VISIBILITY + vector& operator=(const vector& __x); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + vector(vector&& __x) + _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); + _LIBCPP_INLINE_VISIBILITY + vector(vector&& __x, const allocator_type& __a); + _LIBCPP_INLINE_VISIBILITY + vector& operator=(vector&& __x) + _NOEXCEPT_( + __alloc_traits::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable<allocator_type>::value); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + _LIBCPP_INLINE_VISIBILITY + vector& operator=(initializer_list<value_type> __il) + {assign(__il.begin(), __il.end()); return *this;} +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + + template <class _InputIterator> + typename enable_if + < + __is_input_iterator <_InputIterator>::value && + !__is_forward_iterator<_InputIterator>::value, + void + >::type + assign(_InputIterator __first, _InputIterator __last); + template <class _ForwardIterator> + typename enable_if + < + __is_forward_iterator<_ForwardIterator>::value, + void + >::type + assign(_ForwardIterator __first, _ForwardIterator __last); + + void assign(size_type __n, const_reference __u); +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + _LIBCPP_INLINE_VISIBILITY + void assign(initializer_list<value_type> __il) + {assign(__il.begin(), __il.end());} +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + + _LIBCPP_INLINE_VISIBILITY + allocator_type get_allocator() const _NOEXCEPT + {return this->__alloc();} + + _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY + reverse_iterator rbegin() _NOEXCEPT + {return reverse_iterator(end());} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator rbegin() const _NOEXCEPT + {return const_reverse_iterator(end());} + _LIBCPP_INLINE_VISIBILITY + reverse_iterator rend() _NOEXCEPT + {return reverse_iterator(begin());} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator rend() const _NOEXCEPT + {return const_reverse_iterator(begin());} + + _LIBCPP_INLINE_VISIBILITY + const_iterator cbegin() const _NOEXCEPT + {return begin();} + _LIBCPP_INLINE_VISIBILITY + const_iterator cend() const _NOEXCEPT + {return end();} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator crbegin() const _NOEXCEPT + {return rbegin();} + _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator crend() const _NOEXCEPT + {return rend();} + + _LIBCPP_INLINE_VISIBILITY + size_type size() const _NOEXCEPT + {return static_cast<size_type>(this->__end_ - this->__begin_);} + _LIBCPP_INLINE_VISIBILITY + size_type capacity() const _NOEXCEPT + {return __base::capacity();} + _LIBCPP_INLINE_VISIBILITY + bool empty() const _NOEXCEPT + {return this->__begin_ == this->__end_;} + size_type max_size() const _NOEXCEPT; + void reserve(size_type __n); + void shrink_to_fit() _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n); + _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const; + reference at(size_type __n); + const_reference at(size_type __n) const; + + _LIBCPP_INLINE_VISIBILITY reference front() + { + _LIBCPP_ASSERT(!empty(), "front() called for empty vector"); + return *this->__begin_; + } + _LIBCPP_INLINE_VISIBILITY const_reference front() const + { + _LIBCPP_ASSERT(!empty(), "front() called for empty vector"); + return *this->__begin_; + } + _LIBCPP_INLINE_VISIBILITY reference back() + { + _LIBCPP_ASSERT(!empty(), "back() called for empty vector"); + return *(this->__end_ - 1); + } + _LIBCPP_INLINE_VISIBILITY const_reference back() const + { + _LIBCPP_ASSERT(!empty(), "back() called for empty vector"); + return *(this->__end_ - 1); + } + + _LIBCPP_INLINE_VISIBILITY + value_type* data() _NOEXCEPT + {return _VSTD::__to_raw_pointer(this->__begin_);} + _LIBCPP_INLINE_VISIBILITY + const value_type* data() const _NOEXCEPT + {return _VSTD::__to_raw_pointer(this->__begin_);} + + _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + void push_back(value_type&& __x); +#ifndef _LIBCPP_HAS_NO_VARIADICS + template <class... _Args> + void emplace_back(_Args&&... __args); +#endif // _LIBCPP_HAS_NO_VARIADICS +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + void pop_back(); + + iterator insert(const_iterator __position, const_reference __x); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + iterator insert(const_iterator __position, value_type&& __x); +#ifndef _LIBCPP_HAS_NO_VARIADICS + template <class... _Args> + iterator emplace(const_iterator __position, _Args&&... __args); +#endif // _LIBCPP_HAS_NO_VARIADICS +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + iterator insert(const_iterator __position, size_type __n, const_reference __x); + template <class _InputIterator> + typename enable_if + < + __is_input_iterator <_InputIterator>::value && + !__is_forward_iterator<_InputIterator>::value, + iterator + >::type + insert(const_iterator __position, _InputIterator __first, _InputIterator __last); + template <class _ForwardIterator> + typename enable_if + < + __is_forward_iterator<_ForwardIterator>::value, + iterator + >::type + insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last); +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + _LIBCPP_INLINE_VISIBILITY + iterator insert(const_iterator __position, initializer_list<value_type> __il) + {return insert(__position, __il.begin(), __il.end());} +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + + _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position); + iterator erase(const_iterator __first, const_iterator __last); + + _LIBCPP_INLINE_VISIBILITY + void clear() _NOEXCEPT + { + __base::clear(); + __invalidate_all_iterators(); + } + + void resize(size_type __sz); + void resize(size_type __sz, const_reference __x); + + void swap(vector&) + _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || + __is_nothrow_swappable<allocator_type>::value); + + bool __invariants() const; + +#if _LIBCPP_DEBUG_LEVEL >= 2 + + bool __dereferenceable(const const_iterator* __i) const; + bool __decrementable(const const_iterator* __i) const; + bool __addable(const const_iterator* __i, ptrdiff_t __n) const; + bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const; + +#endif // _LIBCPP_DEBUG_LEVEL >= 2 + +private: + _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators(); + void allocate(size_type __n); + void deallocate() _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const; + void __construct_at_end(size_type __n); + void __construct_at_end(size_type __n, const_reference __x); + template <class _ForwardIterator> + typename enable_if + < + __is_forward_iterator<_ForwardIterator>::value, + void + >::type + __construct_at_end(_ForwardIterator __first, _ForwardIterator __last); + void __move_construct_at_end(pointer __first, pointer __last); + void __append(size_type __n); + void __append(size_type __n, const_reference __x); + _LIBCPP_INLINE_VISIBILITY + iterator __make_iter(pointer __p) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + const_iterator __make_iter(const_pointer __p) const _NOEXCEPT; + void __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v); + pointer __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p); + void __move_range(pointer __from_s, pointer __from_e, pointer __to); + void __move_assign(vector& __c, true_type) + _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); + void __move_assign(vector& __c, false_type); + _LIBCPP_INLINE_VISIBILITY + void __destruct_at_end(const_pointer __new_last) _NOEXCEPT + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + __c_node* __c = __get_db()->__find_c_and_lock(this); + for (__i_node** __p = __c->end_; __p != __c->beg_; ) + { + --__p; + const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_); + if (__i->base() > __new_last) + { + (*__p)->__c_ = nullptr; + if (--__c->end_ != __p) + memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); + } + } + __get_db()->unlock(); +#endif + __base::__destruct_at_end(__new_last); + } +}; + +template <class _Tp, class _Allocator> +void +vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v) +{ + for (pointer __p = this->__end_; this->__begin_ < __p;) + __v.push_front(_VSTD::move_if_noexcept(*--__p)); + _VSTD::swap(this->__begin_, __v.__begin_); + _VSTD::swap(this->__end_, __v.__end_); + _VSTD::swap(this->__end_cap(), __v.__end_cap()); + __v.__first_ = __v.__begin_; + __invalidate_all_iterators(); +} + +template <class _Tp, class _Allocator> +typename vector<_Tp, _Allocator>::pointer +vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p) +{ + pointer __r = __v.__begin_; + for (pointer __i = __p; this->__begin_ < __i;) + __v.push_front(_VSTD::move_if_noexcept(*--__i)); + for (pointer __i = __p; __i < this->__end_; ++__i) + __v.push_back(_VSTD::move_if_noexcept(*__i)); + _VSTD::swap(this->__begin_, __v.__begin_); + _VSTD::swap(this->__end_, __v.__end_); + _VSTD::swap(this->__end_cap(), __v.__end_cap()); + __v.__first_ = __v.__begin_; + __invalidate_all_iterators(); + return __r; +} + +// Allocate space for __n objects +// throws length_error if __n > max_size() +// throws (probably bad_alloc) if memory run out +// Precondition: __begin_ == __end_ == __end_cap() == 0 +// Precondition: __n > 0 +// Postcondition: capacity() == __n +// Postcondition: size() == 0 +template <class _Tp, class _Allocator> +void +vector<_Tp, _Allocator>::allocate(size_type __n) +{ + if (__n > max_size()) + this->__throw_length_error(); + this->__begin_ = this->__end_ = __alloc_traits::allocate(this->__alloc(), __n); + this->__end_cap() = this->__begin_ + __n; +} + +template <class _Tp, class _Allocator> +void +vector<_Tp, _Allocator>::deallocate() _NOEXCEPT +{ + if (this->__begin_ != 0) + { + clear(); + __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity()); + this->__begin_ = this->__end_ = this->__end_cap() = 0; + } +} + +template <class _Tp, class _Allocator> +typename vector<_Tp, _Allocator>::size_type +vector<_Tp, _Allocator>::max_size() const _NOEXCEPT +{ + return _VSTD::min<size_type>(__alloc_traits::max_size(this->__alloc()), numeric_limits<size_type>::max() / 2); // end() >= begin(), always +} + +// Precondition: __new_size > capacity() +template <class _Tp, class _Allocator> +_LIBCPP_INLINE_VISIBILITY inline +typename vector<_Tp, _Allocator>::size_type +vector<_Tp, _Allocator>::__recommend(size_type __new_size) const +{ + const size_type __ms = max_size(); + if (__new_size > __ms) + this->__throw_length_error(); + const size_type __cap = capacity(); + if (__cap >= __ms / 2) + return __ms; + return _VSTD::max<size_type>(2*__cap, __new_size); +} + +// Default constructs __n objects starting at __end_ +// throws if construction throws +// Precondition: __n > 0 +// Precondition: size() + __n <= capacity() +// Postcondition: size() == size() + __n +template <class _Tp, class _Allocator> +void +vector<_Tp, _Allocator>::__construct_at_end(size_type __n) +{ + allocator_type& __a = this->__alloc(); + do + { + __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_)); + ++this->__end_; + --__n; + } while (__n > 0); +} + +// Copy constructs __n objects starting at __end_ from __x +// throws if construction throws +// Precondition: __n > 0 +// Precondition: size() + __n <= capacity() +// Postcondition: size() == old size() + __n +// Postcondition: [i] == __x for all i in [size() - __n, __n) +template <class _Tp, class _Allocator> +_LIBCPP_INLINE_VISIBILITY inline +void +vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x) +{ + allocator_type& __a = this->__alloc(); + do + { + __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), __x); + ++this->__end_; + --__n; + } while (__n > 0); +} + +template <class _Tp, class _Allocator> +template <class _ForwardIterator> +typename enable_if +< + __is_forward_iterator<_ForwardIterator>::value, + void +>::type +vector<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last) +{ + allocator_type& __a = this->__alloc(); + for (; __first != __last; ++__first) + { + __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), *__first); + ++this->__end_; + } +} + +template <class _Tp, class _Allocator> +void +vector<_Tp, _Allocator>::__move_construct_at_end(pointer __first, pointer __last) +{ + allocator_type& __a = this->__alloc(); + for (; __first != __last; ++__first) + { + __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), + _VSTD::move(*__first)); + ++this->__end_; + } +} + +// Default constructs __n objects starting at __end_ +// throws if construction throws +// Postcondition: size() == size() + __n +// Exception safety: strong. +template <class _Tp, class _Allocator> +void +vector<_Tp, _Allocator>::__append(size_type __n) +{ + if (static_cast<size_type>(this->__en |