14684ddb6SLionel Sambuc// -*- C++ -*- 24684ddb6SLionel Sambuc//===------------------------------ vector --------------------------------===// 34684ddb6SLionel Sambuc// 44684ddb6SLionel Sambuc// The LLVM Compiler Infrastructure 54684ddb6SLionel Sambuc// 64684ddb6SLionel Sambuc// This file is dual licensed under the MIT and the University of Illinois Open 74684ddb6SLionel Sambuc// Source Licenses. See LICENSE.TXT for details. 84684ddb6SLionel Sambuc// 94684ddb6SLionel Sambuc//===----------------------------------------------------------------------===// 104684ddb6SLionel Sambuc 114684ddb6SLionel Sambuc#ifndef _LIBCPP_VECTOR 124684ddb6SLionel Sambuc#define _LIBCPP_VECTOR 134684ddb6SLionel Sambuc 144684ddb6SLionel Sambuc/* 154684ddb6SLionel Sambuc vector synopsis 164684ddb6SLionel Sambuc 174684ddb6SLionel Sambucnamespace std 184684ddb6SLionel Sambuc{ 194684ddb6SLionel Sambuc 204684ddb6SLionel Sambuctemplate <class T, class Allocator = allocator<T> > 214684ddb6SLionel Sambucclass vector 224684ddb6SLionel Sambuc{ 234684ddb6SLionel Sambucpublic: 244684ddb6SLionel Sambuc typedef T value_type; 254684ddb6SLionel Sambuc typedef Allocator allocator_type; 264684ddb6SLionel Sambuc typedef typename allocator_type::reference reference; 274684ddb6SLionel Sambuc typedef typename allocator_type::const_reference const_reference; 284684ddb6SLionel Sambuc typedef implementation-defined iterator; 294684ddb6SLionel Sambuc typedef implementation-defined const_iterator; 304684ddb6SLionel Sambuc typedef typename allocator_type::size_type size_type; 314684ddb6SLionel Sambuc typedef typename allocator_type::difference_type difference_type; 324684ddb6SLionel Sambuc typedef typename allocator_type::pointer pointer; 334684ddb6SLionel Sambuc typedef typename allocator_type::const_pointer const_pointer; 344684ddb6SLionel Sambuc typedef std::reverse_iterator<iterator> reverse_iterator; 354684ddb6SLionel Sambuc typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 364684ddb6SLionel Sambuc 374684ddb6SLionel Sambuc vector() 384684ddb6SLionel Sambuc noexcept(is_nothrow_default_constructible<allocator_type>::value); 394684ddb6SLionel Sambuc explicit vector(const allocator_type&); 404684ddb6SLionel Sambuc explicit vector(size_type n); 414684ddb6SLionel Sambuc explicit vector(size_type n, const allocator_type&); // C++14 424684ddb6SLionel Sambuc vector(size_type n, const value_type& value, const allocator_type& = allocator_type()); 434684ddb6SLionel Sambuc template <class InputIterator> 444684ddb6SLionel Sambuc vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type()); 454684ddb6SLionel Sambuc vector(const vector& x); 464684ddb6SLionel Sambuc vector(vector&& x) 474684ddb6SLionel Sambuc noexcept(is_nothrow_move_constructible<allocator_type>::value); 484684ddb6SLionel Sambuc vector(initializer_list<value_type> il); 494684ddb6SLionel Sambuc vector(initializer_list<value_type> il, const allocator_type& a); 504684ddb6SLionel Sambuc ~vector(); 514684ddb6SLionel Sambuc vector& operator=(const vector& x); 524684ddb6SLionel Sambuc vector& operator=(vector&& x) 534684ddb6SLionel Sambuc noexcept( 54*0a6a1f1dSLionel Sambuc allocator_type::propagate_on_container_move_assignment::value || 55*0a6a1f1dSLionel Sambuc allocator_type::is_always_equal::value); // C++17 564684ddb6SLionel Sambuc vector& operator=(initializer_list<value_type> il); 574684ddb6SLionel Sambuc template <class InputIterator> 584684ddb6SLionel Sambuc void assign(InputIterator first, InputIterator last); 594684ddb6SLionel Sambuc void assign(size_type n, const value_type& u); 604684ddb6SLionel Sambuc void assign(initializer_list<value_type> il); 614684ddb6SLionel Sambuc 624684ddb6SLionel Sambuc allocator_type get_allocator() const noexcept; 634684ddb6SLionel Sambuc 644684ddb6SLionel Sambuc iterator begin() noexcept; 654684ddb6SLionel Sambuc const_iterator begin() const noexcept; 664684ddb6SLionel Sambuc iterator end() noexcept; 674684ddb6SLionel Sambuc const_iterator end() const noexcept; 684684ddb6SLionel Sambuc 694684ddb6SLionel Sambuc reverse_iterator rbegin() noexcept; 704684ddb6SLionel Sambuc const_reverse_iterator rbegin() const noexcept; 714684ddb6SLionel Sambuc reverse_iterator rend() noexcept; 724684ddb6SLionel Sambuc const_reverse_iterator rend() const noexcept; 734684ddb6SLionel Sambuc 744684ddb6SLionel Sambuc const_iterator cbegin() const noexcept; 754684ddb6SLionel Sambuc const_iterator cend() const noexcept; 764684ddb6SLionel Sambuc const_reverse_iterator crbegin() const noexcept; 774684ddb6SLionel Sambuc const_reverse_iterator crend() const noexcept; 784684ddb6SLionel Sambuc 794684ddb6SLionel Sambuc size_type size() const noexcept; 804684ddb6SLionel Sambuc size_type max_size() const noexcept; 814684ddb6SLionel Sambuc size_type capacity() const noexcept; 824684ddb6SLionel Sambuc bool empty() const noexcept; 834684ddb6SLionel Sambuc void reserve(size_type n); 844684ddb6SLionel Sambuc void shrink_to_fit() noexcept; 854684ddb6SLionel Sambuc 864684ddb6SLionel Sambuc reference operator[](size_type n); 874684ddb6SLionel Sambuc const_reference operator[](size_type n) const; 884684ddb6SLionel Sambuc reference at(size_type n); 894684ddb6SLionel Sambuc const_reference at(size_type n) const; 904684ddb6SLionel Sambuc 914684ddb6SLionel Sambuc reference front(); 924684ddb6SLionel Sambuc const_reference front() const; 934684ddb6SLionel Sambuc reference back(); 944684ddb6SLionel Sambuc const_reference back() const; 954684ddb6SLionel Sambuc 964684ddb6SLionel Sambuc value_type* data() noexcept; 974684ddb6SLionel Sambuc const value_type* data() const noexcept; 984684ddb6SLionel Sambuc 994684ddb6SLionel Sambuc void push_back(const value_type& x); 1004684ddb6SLionel Sambuc void push_back(value_type&& x); 1014684ddb6SLionel Sambuc template <class... Args> 1024684ddb6SLionel Sambuc void emplace_back(Args&&... args); 1034684ddb6SLionel Sambuc void pop_back(); 1044684ddb6SLionel Sambuc 1054684ddb6SLionel Sambuc template <class... Args> iterator emplace(const_iterator position, Args&&... args); 1064684ddb6SLionel Sambuc iterator insert(const_iterator position, const value_type& x); 1074684ddb6SLionel Sambuc iterator insert(const_iterator position, value_type&& x); 1084684ddb6SLionel Sambuc iterator insert(const_iterator position, size_type n, const value_type& x); 1094684ddb6SLionel Sambuc template <class InputIterator> 1104684ddb6SLionel Sambuc iterator insert(const_iterator position, InputIterator first, InputIterator last); 1114684ddb6SLionel Sambuc iterator insert(const_iterator position, initializer_list<value_type> il); 1124684ddb6SLionel Sambuc 1134684ddb6SLionel Sambuc iterator erase(const_iterator position); 1144684ddb6SLionel Sambuc iterator erase(const_iterator first, const_iterator last); 1154684ddb6SLionel Sambuc 1164684ddb6SLionel Sambuc void clear() noexcept; 1174684ddb6SLionel Sambuc 1184684ddb6SLionel Sambuc void resize(size_type sz); 1194684ddb6SLionel Sambuc void resize(size_type sz, const value_type& c); 1204684ddb6SLionel Sambuc 1214684ddb6SLionel Sambuc void swap(vector&) 122*0a6a1f1dSLionel Sambuc noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value || 123*0a6a1f1dSLionel Sambuc allocator_traits<allocator_type>::is_always_equal::value); // C++17 1244684ddb6SLionel Sambuc 1254684ddb6SLionel Sambuc bool __invariants() const; 1264684ddb6SLionel Sambuc}; 1274684ddb6SLionel Sambuc 1284684ddb6SLionel Sambuctemplate <class Allocator = allocator<T> > 1294684ddb6SLionel Sambucclass vector<bool, Allocator> 1304684ddb6SLionel Sambuc{ 1314684ddb6SLionel Sambucpublic: 1324684ddb6SLionel Sambuc typedef bool value_type; 1334684ddb6SLionel Sambuc typedef Allocator allocator_type; 1344684ddb6SLionel Sambuc typedef implementation-defined iterator; 1354684ddb6SLionel Sambuc typedef implementation-defined const_iterator; 1364684ddb6SLionel Sambuc typedef typename allocator_type::size_type size_type; 1374684ddb6SLionel Sambuc typedef typename allocator_type::difference_type difference_type; 1384684ddb6SLionel Sambuc typedef iterator pointer; 1394684ddb6SLionel Sambuc typedef const_iterator const_pointer; 1404684ddb6SLionel Sambuc typedef std::reverse_iterator<iterator> reverse_iterator; 1414684ddb6SLionel Sambuc typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 1424684ddb6SLionel Sambuc 1434684ddb6SLionel Sambuc class reference 1444684ddb6SLionel Sambuc { 1454684ddb6SLionel Sambuc public: 1464684ddb6SLionel Sambuc reference(const reference&) noexcept; 1474684ddb6SLionel Sambuc operator bool() const noexcept; 1484684ddb6SLionel Sambuc reference& operator=(const bool x) noexcept; 1494684ddb6SLionel Sambuc reference& operator=(const reference& x) noexcept; 1504684ddb6SLionel Sambuc iterator operator&() const noexcept; 1514684ddb6SLionel Sambuc void flip() noexcept; 1524684ddb6SLionel Sambuc }; 1534684ddb6SLionel Sambuc 1544684ddb6SLionel Sambuc class const_reference 1554684ddb6SLionel Sambuc { 1564684ddb6SLionel Sambuc public: 1574684ddb6SLionel Sambuc const_reference(const reference&) noexcept; 1584684ddb6SLionel Sambuc operator bool() const noexcept; 1594684ddb6SLionel Sambuc const_iterator operator&() const noexcept; 1604684ddb6SLionel Sambuc }; 1614684ddb6SLionel Sambuc 1624684ddb6SLionel Sambuc vector() 1634684ddb6SLionel Sambuc noexcept(is_nothrow_default_constructible<allocator_type>::value); 1644684ddb6SLionel Sambuc explicit vector(const allocator_type&); 1654684ddb6SLionel Sambuc explicit vector(size_type n, const allocator_type& a = allocator_type()); // C++14 1664684ddb6SLionel Sambuc vector(size_type n, const value_type& value, const allocator_type& = allocator_type()); 1674684ddb6SLionel Sambuc template <class InputIterator> 1684684ddb6SLionel Sambuc vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type()); 1694684ddb6SLionel Sambuc vector(const vector& x); 1704684ddb6SLionel Sambuc vector(vector&& x) 1714684ddb6SLionel Sambuc noexcept(is_nothrow_move_constructible<allocator_type>::value); 1724684ddb6SLionel Sambuc vector(initializer_list<value_type> il); 1734684ddb6SLionel Sambuc vector(initializer_list<value_type> il, const allocator_type& a); 1744684ddb6SLionel Sambuc ~vector(); 1754684ddb6SLionel Sambuc vector& operator=(const vector& x); 1764684ddb6SLionel Sambuc vector& operator=(vector&& x) 1774684ddb6SLionel Sambuc noexcept( 178*0a6a1f1dSLionel Sambuc allocator_type::propagate_on_container_move_assignment::value || 179*0a6a1f1dSLionel Sambuc allocator_type::is_always_equal::value); // C++17 1804684ddb6SLionel Sambuc vector& operator=(initializer_list<value_type> il); 1814684ddb6SLionel Sambuc template <class InputIterator> 1824684ddb6SLionel Sambuc void assign(InputIterator first, InputIterator last); 1834684ddb6SLionel Sambuc void assign(size_type n, const value_type& u); 1844684ddb6SLionel Sambuc void assign(initializer_list<value_type> il); 1854684ddb6SLionel Sambuc 1864684ddb6SLionel Sambuc allocator_type get_allocator() const noexcept; 1874684ddb6SLionel Sambuc 1884684ddb6SLionel Sambuc iterator begin() noexcept; 1894684ddb6SLionel Sambuc const_iterator begin() const noexcept; 1904684ddb6SLionel Sambuc iterator end() noexcept; 1914684ddb6SLionel Sambuc const_iterator end() const noexcept; 1924684ddb6SLionel Sambuc 1934684ddb6SLionel Sambuc reverse_iterator rbegin() noexcept; 1944684ddb6SLionel Sambuc const_reverse_iterator rbegin() const noexcept; 1954684ddb6SLionel Sambuc reverse_iterator rend() noexcept; 1964684ddb6SLionel Sambuc const_reverse_iterator rend() const noexcept; 1974684ddb6SLionel Sambuc 1984684ddb6SLionel Sambuc const_iterator cbegin() const noexcept; 1994684ddb6SLionel Sambuc const_iterator cend() const noexcept; 2004684ddb6SLionel Sambuc const_reverse_iterator crbegin() const noexcept; 2014684ddb6SLionel Sambuc const_reverse_iterator crend() const noexcept; 2024684ddb6SLionel Sambuc 2034684ddb6SLionel Sambuc size_type size() const noexcept; 2044684ddb6SLionel Sambuc size_type max_size() const noexcept; 2054684ddb6SLionel Sambuc size_type capacity() const noexcept; 2064684ddb6SLionel Sambuc bool empty() const noexcept; 2074684ddb6SLionel Sambuc void reserve(size_type n); 2084684ddb6SLionel Sambuc void shrink_to_fit() noexcept; 2094684ddb6SLionel Sambuc 2104684ddb6SLionel Sambuc reference operator[](size_type n); 2114684ddb6SLionel Sambuc const_reference operator[](size_type n) const; 2124684ddb6SLionel Sambuc reference at(size_type n); 2134684ddb6SLionel Sambuc const_reference at(size_type n) const; 2144684ddb6SLionel Sambuc 2154684ddb6SLionel Sambuc reference front(); 2164684ddb6SLionel Sambuc const_reference front() const; 2174684ddb6SLionel Sambuc reference back(); 2184684ddb6SLionel Sambuc const_reference back() const; 2194684ddb6SLionel Sambuc 2204684ddb6SLionel Sambuc void push_back(const value_type& x); 2214684ddb6SLionel Sambuc template <class... Args> void emplace_back(Args&&... args); // C++14 2224684ddb6SLionel Sambuc void pop_back(); 2234684ddb6SLionel Sambuc 2244684ddb6SLionel Sambuc template <class... Args> iterator emplace(const_iterator position, Args&&... args); // C++14 2254684ddb6SLionel Sambuc iterator insert(const_iterator position, const value_type& x); 2264684ddb6SLionel Sambuc iterator insert(const_iterator position, size_type n, const value_type& x); 2274684ddb6SLionel Sambuc template <class InputIterator> 2284684ddb6SLionel Sambuc iterator insert(const_iterator position, InputIterator first, InputIterator last); 2294684ddb6SLionel Sambuc iterator insert(const_iterator position, initializer_list<value_type> il); 2304684ddb6SLionel Sambuc 2314684ddb6SLionel Sambuc iterator erase(const_iterator position); 2324684ddb6SLionel Sambuc iterator erase(const_iterator first, const_iterator last); 2334684ddb6SLionel Sambuc 2344684ddb6SLionel Sambuc void clear() noexcept; 2354684ddb6SLionel Sambuc 2364684ddb6SLionel Sambuc void resize(size_type sz); 2374684ddb6SLionel Sambuc void resize(size_type sz, value_type x); 2384684ddb6SLionel Sambuc 2394684ddb6SLionel Sambuc void swap(vector&) 240*0a6a1f1dSLionel Sambuc noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value || 241*0a6a1f1dSLionel Sambuc allocator_traits<allocator_type>::is_always_equal::value); // C++17 2424684ddb6SLionel Sambuc void flip() noexcept; 2434684ddb6SLionel Sambuc 2444684ddb6SLionel Sambuc bool __invariants() const; 2454684ddb6SLionel Sambuc}; 2464684ddb6SLionel Sambuc 2474684ddb6SLionel Sambuctemplate <class Allocator> struct hash<std::vector<bool, Allocator>>; 2484684ddb6SLionel Sambuc 2494684ddb6SLionel Sambuctemplate <class T, class Allocator> bool operator==(const vector<T,Allocator>& x, const vector<T,Allocator>& y); 2504684ddb6SLionel Sambuctemplate <class T, class Allocator> bool operator< (const vector<T,Allocator>& x, const vector<T,Allocator>& y); 2514684ddb6SLionel Sambuctemplate <class T, class Allocator> bool operator!=(const vector<T,Allocator>& x, const vector<T,Allocator>& y); 2524684ddb6SLionel Sambuctemplate <class T, class Allocator> bool operator> (const vector<T,Allocator>& x, const vector<T,Allocator>& y); 2534684ddb6SLionel Sambuctemplate <class T, class Allocator> bool operator>=(const vector<T,Allocator>& x, const vector<T,Allocator>& y); 2544684ddb6SLionel Sambuctemplate <class T, class Allocator> bool operator<=(const vector<T,Allocator>& x, const vector<T,Allocator>& y); 2554684ddb6SLionel Sambuc 2564684ddb6SLionel Sambuctemplate <class T, class Allocator> 2574684ddb6SLionel Sambucvoid swap(vector<T,Allocator>& x, vector<T,Allocator>& y) 2584684ddb6SLionel Sambuc noexcept(noexcept(x.swap(y))); 2594684ddb6SLionel Sambuc 2604684ddb6SLionel Sambuc} // std 2614684ddb6SLionel Sambuc 2624684ddb6SLionel Sambuc*/ 2634684ddb6SLionel Sambuc 2644684ddb6SLionel Sambuc#include <__config> 2654684ddb6SLionel Sambuc#include <__bit_reference> 2664684ddb6SLionel Sambuc#include <type_traits> 2674684ddb6SLionel Sambuc#include <climits> 2684684ddb6SLionel Sambuc#include <limits> 2694684ddb6SLionel Sambuc#include <initializer_list> 2704684ddb6SLionel Sambuc#include <memory> 2714684ddb6SLionel Sambuc#include <stdexcept> 2724684ddb6SLionel Sambuc#include <algorithm> 2734684ddb6SLionel Sambuc#include <cstring> 2744684ddb6SLionel Sambuc#include <__split_buffer> 2754684ddb6SLionel Sambuc#include <__functional_base> 2764684ddb6SLionel Sambuc 2774684ddb6SLionel Sambuc#include <__undef_min_max> 2784684ddb6SLionel Sambuc 2794684ddb6SLionel Sambuc#include <__debug> 2804684ddb6SLionel Sambuc 2814684ddb6SLionel Sambuc#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 2824684ddb6SLionel Sambuc#pragma GCC system_header 2834684ddb6SLionel Sambuc#endif 2844684ddb6SLionel Sambuc 2854684ddb6SLionel Sambuc_LIBCPP_BEGIN_NAMESPACE_STD 2864684ddb6SLionel Sambuc 2874684ddb6SLionel Sambuctemplate <bool> 2884684ddb6SLionel Sambucclass __vector_base_common 2894684ddb6SLionel Sambuc{ 2904684ddb6SLionel Sambucprotected: 2914684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE __vector_base_common() {} 2924684ddb6SLionel Sambuc void __throw_length_error() const; 2934684ddb6SLionel Sambuc void __throw_out_of_range() const; 2944684ddb6SLionel Sambuc}; 2954684ddb6SLionel Sambuc 2964684ddb6SLionel Sambuctemplate <bool __b> 2974684ddb6SLionel Sambucvoid 2984684ddb6SLionel Sambuc__vector_base_common<__b>::__throw_length_error() const 2994684ddb6SLionel Sambuc{ 3004684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 3014684ddb6SLionel Sambuc throw length_error("vector"); 3024684ddb6SLionel Sambuc#else 3034684ddb6SLionel Sambuc assert(!"vector length_error"); 3044684ddb6SLionel Sambuc#endif 3054684ddb6SLionel Sambuc} 3064684ddb6SLionel Sambuc 3074684ddb6SLionel Sambuctemplate <bool __b> 3084684ddb6SLionel Sambucvoid 3094684ddb6SLionel Sambuc__vector_base_common<__b>::__throw_out_of_range() const 3104684ddb6SLionel Sambuc{ 3114684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 3124684ddb6SLionel Sambuc throw out_of_range("vector"); 3134684ddb6SLionel Sambuc#else 3144684ddb6SLionel Sambuc assert(!"vector out_of_range"); 3154684ddb6SLionel Sambuc#endif 3164684ddb6SLionel Sambuc} 3174684ddb6SLionel Sambuc 3184684ddb6SLionel Sambuc#ifdef _LIBCPP_MSVC 3194684ddb6SLionel Sambuc#pragma warning( push ) 3204684ddb6SLionel Sambuc#pragma warning( disable: 4231 ) 3214684ddb6SLionel Sambuc#endif // _LIBCPP_MSVC 3224684ddb6SLionel Sambuc_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS __vector_base_common<true>) 3234684ddb6SLionel Sambuc#ifdef _LIBCPP_MSVC 3244684ddb6SLionel Sambuc#pragma warning( pop ) 3254684ddb6SLionel Sambuc#endif // _LIBCPP_MSVC 3264684ddb6SLionel Sambuc 3274684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 3284684ddb6SLionel Sambucclass __vector_base 3294684ddb6SLionel Sambuc : protected __vector_base_common<true> 3304684ddb6SLionel Sambuc{ 3314684ddb6SLionel Sambucprotected: 3324684ddb6SLionel Sambuc typedef _Tp value_type; 3334684ddb6SLionel Sambuc typedef _Allocator allocator_type; 3344684ddb6SLionel Sambuc typedef allocator_traits<allocator_type> __alloc_traits; 3354684ddb6SLionel Sambuc typedef value_type& reference; 3364684ddb6SLionel Sambuc typedef const value_type& const_reference; 3374684ddb6SLionel Sambuc typedef typename __alloc_traits::size_type size_type; 3384684ddb6SLionel Sambuc typedef typename __alloc_traits::difference_type difference_type; 3394684ddb6SLionel Sambuc typedef typename __alloc_traits::pointer pointer; 3404684ddb6SLionel Sambuc typedef typename __alloc_traits::const_pointer const_pointer; 3414684ddb6SLionel Sambuc typedef pointer iterator; 3424684ddb6SLionel Sambuc typedef const_pointer const_iterator; 3434684ddb6SLionel Sambuc 3444684ddb6SLionel Sambuc pointer __begin_; 3454684ddb6SLionel Sambuc pointer __end_; 3464684ddb6SLionel Sambuc __compressed_pair<pointer, allocator_type> __end_cap_; 3474684ddb6SLionel Sambuc 3484684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 3494684ddb6SLionel Sambuc allocator_type& __alloc() _NOEXCEPT 3504684ddb6SLionel Sambuc {return __end_cap_.second();} 3514684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 3524684ddb6SLionel Sambuc const allocator_type& __alloc() const _NOEXCEPT 3534684ddb6SLionel Sambuc {return __end_cap_.second();} 3544684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 3554684ddb6SLionel Sambuc pointer& __end_cap() _NOEXCEPT 3564684ddb6SLionel Sambuc {return __end_cap_.first();} 3574684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 3584684ddb6SLionel Sambuc const pointer& __end_cap() const _NOEXCEPT 3594684ddb6SLionel Sambuc {return __end_cap_.first();} 3604684ddb6SLionel Sambuc 3614684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 3624684ddb6SLionel Sambuc __vector_base() 3634684ddb6SLionel Sambuc _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value); 3644684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY __vector_base(const allocator_type& __a); 3654684ddb6SLionel Sambuc ~__vector_base(); 3664684ddb6SLionel Sambuc 3674684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 3684684ddb6SLionel Sambuc void clear() _NOEXCEPT {__destruct_at_end(__begin_);} 3694684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 3704684ddb6SLionel Sambuc size_type capacity() const _NOEXCEPT 3714684ddb6SLionel Sambuc {return static_cast<size_type>(__end_cap() - __begin_);} 3724684ddb6SLionel Sambuc 3734684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 3744684ddb6SLionel Sambuc void __destruct_at_end(pointer __new_last) _NOEXCEPT; 3754684ddb6SLionel Sambuc 3764684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 3774684ddb6SLionel Sambuc void __copy_assign_alloc(const __vector_base& __c) 3784684ddb6SLionel Sambuc {__copy_assign_alloc(__c, integral_constant<bool, 3794684ddb6SLionel Sambuc __alloc_traits::propagate_on_container_copy_assignment::value>());} 3804684ddb6SLionel Sambuc 3814684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 3824684ddb6SLionel Sambuc void __move_assign_alloc(__vector_base& __c) 3834684ddb6SLionel Sambuc _NOEXCEPT_( 3844684ddb6SLionel Sambuc !__alloc_traits::propagate_on_container_move_assignment::value || 3854684ddb6SLionel Sambuc is_nothrow_move_assignable<allocator_type>::value) 3864684ddb6SLionel Sambuc {__move_assign_alloc(__c, integral_constant<bool, 3874684ddb6SLionel Sambuc __alloc_traits::propagate_on_container_move_assignment::value>());} 3884684ddb6SLionel Sambucprivate: 3894684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 3904684ddb6SLionel Sambuc void __copy_assign_alloc(const __vector_base& __c, true_type) 3914684ddb6SLionel Sambuc { 3924684ddb6SLionel Sambuc if (__alloc() != __c.__alloc()) 3934684ddb6SLionel Sambuc { 3944684ddb6SLionel Sambuc clear(); 3954684ddb6SLionel Sambuc __alloc_traits::deallocate(__alloc(), __begin_, capacity()); 3964684ddb6SLionel Sambuc __begin_ = __end_ = __end_cap() = nullptr; 3974684ddb6SLionel Sambuc } 3984684ddb6SLionel Sambuc __alloc() = __c.__alloc(); 3994684ddb6SLionel Sambuc } 4004684ddb6SLionel Sambuc 4014684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 4024684ddb6SLionel Sambuc void __copy_assign_alloc(const __vector_base&, false_type) 4034684ddb6SLionel Sambuc {} 4044684ddb6SLionel Sambuc 4054684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 4064684ddb6SLionel Sambuc void __move_assign_alloc(__vector_base& __c, true_type) 4074684ddb6SLionel Sambuc _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) 4084684ddb6SLionel Sambuc { 4094684ddb6SLionel Sambuc __alloc() = _VSTD::move(__c.__alloc()); 4104684ddb6SLionel Sambuc } 4114684ddb6SLionel Sambuc 4124684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 4134684ddb6SLionel Sambuc void __move_assign_alloc(__vector_base&, false_type) 4144684ddb6SLionel Sambuc _NOEXCEPT 4154684ddb6SLionel Sambuc {} 4164684ddb6SLionel Sambuc}; 4174684ddb6SLionel Sambuc 4184684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 4194684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 4204684ddb6SLionel Sambucvoid 4214684ddb6SLionel Sambuc__vector_base<_Tp, _Allocator>::__destruct_at_end(pointer __new_last) _NOEXCEPT 4224684ddb6SLionel Sambuc{ 4234684ddb6SLionel Sambuc while (__new_last != __end_) 4244684ddb6SLionel Sambuc __alloc_traits::destroy(__alloc(), _VSTD::__to_raw_pointer(--__end_)); 4254684ddb6SLionel Sambuc} 4264684ddb6SLionel Sambuc 4274684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 4284684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 4294684ddb6SLionel Sambuc__vector_base<_Tp, _Allocator>::__vector_base() 4304684ddb6SLionel Sambuc _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) 4314684ddb6SLionel Sambuc : __begin_(nullptr), 4324684ddb6SLionel Sambuc __end_(nullptr), 4334684ddb6SLionel Sambuc __end_cap_(nullptr) 4344684ddb6SLionel Sambuc{ 4354684ddb6SLionel Sambuc} 4364684ddb6SLionel Sambuc 4374684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 4384684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 4394684ddb6SLionel Sambuc__vector_base<_Tp, _Allocator>::__vector_base(const allocator_type& __a) 4404684ddb6SLionel Sambuc : __begin_(nullptr), 4414684ddb6SLionel Sambuc __end_(nullptr), 4424684ddb6SLionel Sambuc __end_cap_(nullptr, __a) 4434684ddb6SLionel Sambuc{ 4444684ddb6SLionel Sambuc} 4454684ddb6SLionel Sambuc 4464684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 4474684ddb6SLionel Sambuc__vector_base<_Tp, _Allocator>::~__vector_base() 4484684ddb6SLionel Sambuc{ 4494684ddb6SLionel Sambuc if (__begin_ != nullptr) 4504684ddb6SLionel Sambuc { 4514684ddb6SLionel Sambuc clear(); 4524684ddb6SLionel Sambuc __alloc_traits::deallocate(__alloc(), __begin_, capacity()); 4534684ddb6SLionel Sambuc } 4544684ddb6SLionel Sambuc} 4554684ddb6SLionel Sambuc 4564684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator = allocator<_Tp> > 4574684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY vector 4584684ddb6SLionel Sambuc : private __vector_base<_Tp, _Allocator> 4594684ddb6SLionel Sambuc{ 4604684ddb6SLionel Sambucprivate: 4614684ddb6SLionel Sambuc typedef __vector_base<_Tp, _Allocator> __base; 462*0a6a1f1dSLionel Sambuc typedef allocator<_Tp> __default_allocator_type; 4634684ddb6SLionel Sambucpublic: 4644684ddb6SLionel Sambuc typedef vector __self; 4654684ddb6SLionel Sambuc typedef _Tp value_type; 4664684ddb6SLionel Sambuc typedef _Allocator allocator_type; 4674684ddb6SLionel Sambuc typedef typename __base::__alloc_traits __alloc_traits; 4684684ddb6SLionel Sambuc typedef typename __base::reference reference; 4694684ddb6SLionel Sambuc typedef typename __base::const_reference const_reference; 4704684ddb6SLionel Sambuc typedef typename __base::size_type size_type; 4714684ddb6SLionel Sambuc typedef typename __base::difference_type difference_type; 4724684ddb6SLionel Sambuc typedef typename __base::pointer pointer; 4734684ddb6SLionel Sambuc typedef typename __base::const_pointer const_pointer; 4744684ddb6SLionel Sambuc typedef __wrap_iter<pointer> iterator; 4754684ddb6SLionel Sambuc typedef __wrap_iter<const_pointer> const_iterator; 4764684ddb6SLionel Sambuc typedef _VSTD::reverse_iterator<iterator> reverse_iterator; 4774684ddb6SLionel Sambuc typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; 4784684ddb6SLionel Sambuc 4794684ddb6SLionel Sambuc static_assert((is_same<typename allocator_type::value_type, value_type>::value), 4804684ddb6SLionel Sambuc "Allocator::value_type must be same type as value_type"); 4814684ddb6SLionel Sambuc 4824684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 483*0a6a1f1dSLionel Sambuc vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) 4844684ddb6SLionel Sambuc { 4854684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2 4864684ddb6SLionel Sambuc __get_db()->__insert_c(this); 4874684ddb6SLionel Sambuc#endif 4884684ddb6SLionel Sambuc } 4894684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a) 490*0a6a1f1dSLionel Sambuc#if _LIBCPP_STD_VER <= 14 491*0a6a1f1dSLionel Sambuc _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value) 492*0a6a1f1dSLionel Sambuc#else 493*0a6a1f1dSLionel Sambuc _NOEXCEPT 494*0a6a1f1dSLionel Sambuc#endif 4954684ddb6SLionel Sambuc : __base(__a) 4964684ddb6SLionel Sambuc { 4974684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2 4984684ddb6SLionel Sambuc __get_db()->__insert_c(this); 4994684ddb6SLionel Sambuc#endif 5004684ddb6SLionel Sambuc } 5014684ddb6SLionel Sambuc explicit vector(size_type __n); 5024684ddb6SLionel Sambuc#if _LIBCPP_STD_VER > 11 5034684ddb6SLionel Sambuc explicit vector(size_type __n, const allocator_type& __a); 5044684ddb6SLionel Sambuc#endif 5054684ddb6SLionel Sambuc vector(size_type __n, const_reference __x); 5064684ddb6SLionel Sambuc vector(size_type __n, const_reference __x, const allocator_type& __a); 5074684ddb6SLionel Sambuc template <class _InputIterator> 5084684ddb6SLionel Sambuc vector(_InputIterator __first, 5094684ddb6SLionel Sambuc typename enable_if<__is_input_iterator <_InputIterator>::value && 5104684ddb6SLionel Sambuc !__is_forward_iterator<_InputIterator>::value && 5114684ddb6SLionel Sambuc is_constructible< 5124684ddb6SLionel Sambuc value_type, 5134684ddb6SLionel Sambuc typename iterator_traits<_InputIterator>::reference>::value, 5144684ddb6SLionel Sambuc _InputIterator>::type __last); 5154684ddb6SLionel Sambuc template <class _InputIterator> 5164684ddb6SLionel Sambuc vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, 5174684ddb6SLionel Sambuc typename enable_if<__is_input_iterator <_InputIterator>::value && 5184684ddb6SLionel Sambuc !__is_forward_iterator<_InputIterator>::value && 5194684ddb6SLionel Sambuc is_constructible< 5204684ddb6SLionel Sambuc value_type, 5214684ddb6SLionel Sambuc typename iterator_traits<_InputIterator>::reference>::value>::type* = 0); 5224684ddb6SLionel Sambuc template <class _ForwardIterator> 5234684ddb6SLionel Sambuc vector(_ForwardIterator __first, 5244684ddb6SLionel Sambuc typename enable_if<__is_forward_iterator<_ForwardIterator>::value && 5254684ddb6SLionel Sambuc is_constructible< 5264684ddb6SLionel Sambuc value_type, 5274684ddb6SLionel Sambuc typename iterator_traits<_ForwardIterator>::reference>::value, 5284684ddb6SLionel Sambuc _ForwardIterator>::type __last); 5294684ddb6SLionel Sambuc template <class _ForwardIterator> 5304684ddb6SLionel Sambuc vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, 5314684ddb6SLionel Sambuc typename enable_if<__is_forward_iterator<_ForwardIterator>::value && 5324684ddb6SLionel Sambuc is_constructible< 5334684ddb6SLionel Sambuc value_type, 5344684ddb6SLionel Sambuc typename iterator_traits<_ForwardIterator>::reference>::value>::type* = 0); 5354684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 5364684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 5374684ddb6SLionel Sambuc vector(initializer_list<value_type> __il); 5384684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 5394684ddb6SLionel Sambuc vector(initializer_list<value_type> __il, const allocator_type& __a); 5404684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 5414684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2 5424684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 5434684ddb6SLionel Sambuc ~vector() 5444684ddb6SLionel Sambuc { 5454684ddb6SLionel Sambuc __get_db()->__erase_c(this); 5464684ddb6SLionel Sambuc } 5474684ddb6SLionel Sambuc#endif 5484684ddb6SLionel Sambuc 5494684ddb6SLionel Sambuc vector(const vector& __x); 5504684ddb6SLionel Sambuc vector(const vector& __x, const allocator_type& __a); 5514684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 5524684ddb6SLionel Sambuc vector& operator=(const vector& __x); 5534684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 5544684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 5554684ddb6SLionel Sambuc vector(vector&& __x) 556*0a6a1f1dSLionel Sambuc#if _LIBCPP_STD_VER > 14 557*0a6a1f1dSLionel Sambuc _NOEXCEPT; 558*0a6a1f1dSLionel Sambuc#else 5594684ddb6SLionel Sambuc _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); 560*0a6a1f1dSLionel Sambuc#endif 5614684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 5624684ddb6SLionel Sambuc vector(vector&& __x, const allocator_type& __a); 5634684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 5644684ddb6SLionel Sambuc vector& operator=(vector&& __x) 565*0a6a1f1dSLionel Sambuc _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)); 5664684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 5674684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 5684684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 5694684ddb6SLionel Sambuc vector& operator=(initializer_list<value_type> __il) 5704684ddb6SLionel Sambuc {assign(__il.begin(), __il.end()); return *this;} 5714684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 5724684ddb6SLionel Sambuc 5734684ddb6SLionel Sambuc template <class _InputIterator> 5744684ddb6SLionel Sambuc typename enable_if 5754684ddb6SLionel Sambuc < 5764684ddb6SLionel Sambuc __is_input_iterator <_InputIterator>::value && 5774684ddb6SLionel Sambuc !__is_forward_iterator<_InputIterator>::value && 5784684ddb6SLionel Sambuc is_constructible< 5794684ddb6SLionel Sambuc value_type, 5804684ddb6SLionel Sambuc typename iterator_traits<_InputIterator>::reference>::value, 5814684ddb6SLionel Sambuc void 5824684ddb6SLionel Sambuc >::type 5834684ddb6SLionel Sambuc assign(_InputIterator __first, _InputIterator __last); 5844684ddb6SLionel Sambuc template <class _ForwardIterator> 5854684ddb6SLionel Sambuc typename enable_if 5864684ddb6SLionel Sambuc < 5874684ddb6SLionel Sambuc __is_forward_iterator<_ForwardIterator>::value && 5884684ddb6SLionel Sambuc is_constructible< 5894684ddb6SLionel Sambuc value_type, 5904684ddb6SLionel Sambuc typename iterator_traits<_ForwardIterator>::reference>::value, 5914684ddb6SLionel Sambuc void 5924684ddb6SLionel Sambuc >::type 5934684ddb6SLionel Sambuc assign(_ForwardIterator __first, _ForwardIterator __last); 5944684ddb6SLionel Sambuc 5954684ddb6SLionel Sambuc void assign(size_type __n, const_reference __u); 5964684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 5974684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 5984684ddb6SLionel Sambuc void assign(initializer_list<value_type> __il) 5994684ddb6SLionel Sambuc {assign(__il.begin(), __il.end());} 6004684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 6014684ddb6SLionel Sambuc 6024684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 6034684ddb6SLionel Sambuc allocator_type get_allocator() const _NOEXCEPT 6044684ddb6SLionel Sambuc {return this->__alloc();} 6054684ddb6SLionel Sambuc 6064684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT; 6074684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT; 6084684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT; 6094684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT; 6104684ddb6SLionel Sambuc 6114684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 6124684ddb6SLionel Sambuc reverse_iterator rbegin() _NOEXCEPT 6134684ddb6SLionel Sambuc {return reverse_iterator(end());} 6144684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 6154684ddb6SLionel Sambuc const_reverse_iterator rbegin() const _NOEXCEPT 6164684ddb6SLionel Sambuc {return const_reverse_iterator(end());} 6174684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 6184684ddb6SLionel Sambuc reverse_iterator rend() _NOEXCEPT 6194684ddb6SLionel Sambuc {return reverse_iterator(begin());} 6204684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 6214684ddb6SLionel Sambuc const_reverse_iterator rend() const _NOEXCEPT 6224684ddb6SLionel Sambuc {return const_reverse_iterator(begin());} 6234684ddb6SLionel Sambuc 6244684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 6254684ddb6SLionel Sambuc const_iterator cbegin() const _NOEXCEPT 6264684ddb6SLionel Sambuc {return begin();} 6274684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 6284684ddb6SLionel Sambuc const_iterator cend() const _NOEXCEPT 6294684ddb6SLionel Sambuc {return end();} 6304684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 6314684ddb6SLionel Sambuc const_reverse_iterator crbegin() const _NOEXCEPT 6324684ddb6SLionel Sambuc {return rbegin();} 6334684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 6344684ddb6SLionel Sambuc const_reverse_iterator crend() const _NOEXCEPT 6354684ddb6SLionel Sambuc {return rend();} 6364684ddb6SLionel Sambuc 6374684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 6384684ddb6SLionel Sambuc size_type size() const _NOEXCEPT 6394684ddb6SLionel Sambuc {return static_cast<size_type>(this->__end_ - this->__begin_);} 6404684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 6414684ddb6SLionel Sambuc size_type capacity() const _NOEXCEPT 6424684ddb6SLionel Sambuc {return __base::capacity();} 6434684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 6444684ddb6SLionel Sambuc bool empty() const _NOEXCEPT 6454684ddb6SLionel Sambuc {return this->__begin_ == this->__end_;} 6464684ddb6SLionel Sambuc size_type max_size() const _NOEXCEPT; 6474684ddb6SLionel Sambuc void reserve(size_type __n); 6484684ddb6SLionel Sambuc void shrink_to_fit() _NOEXCEPT; 6494684ddb6SLionel Sambuc 6504684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n); 6514684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const; 6524684ddb6SLionel Sambuc reference at(size_type __n); 6534684ddb6SLionel Sambuc const_reference at(size_type __n) const; 6544684ddb6SLionel Sambuc 6554684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY reference front() 6564684ddb6SLionel Sambuc { 6574684ddb6SLionel Sambuc _LIBCPP_ASSERT(!empty(), "front() called for empty vector"); 6584684ddb6SLionel Sambuc return *this->__begin_; 6594684ddb6SLionel Sambuc } 6604684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY const_reference front() const 6614684ddb6SLionel Sambuc { 6624684ddb6SLionel Sambuc _LIBCPP_ASSERT(!empty(), "front() called for empty vector"); 6634684ddb6SLionel Sambuc return *this->__begin_; 6644684ddb6SLionel Sambuc } 6654684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY reference back() 6664684ddb6SLionel Sambuc { 6674684ddb6SLionel Sambuc _LIBCPP_ASSERT(!empty(), "back() called for empty vector"); 6684684ddb6SLionel Sambuc return *(this->__end_ - 1); 6694684ddb6SLionel Sambuc } 6704684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY const_reference back() const 6714684ddb6SLionel Sambuc { 6724684ddb6SLionel Sambuc _LIBCPP_ASSERT(!empty(), "back() called for empty vector"); 6734684ddb6SLionel Sambuc return *(this->__end_ - 1); 6744684ddb6SLionel Sambuc } 6754684ddb6SLionel Sambuc 6764684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 6774684ddb6SLionel Sambuc value_type* data() _NOEXCEPT 6784684ddb6SLionel Sambuc {return _VSTD::__to_raw_pointer(this->__begin_);} 6794684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 6804684ddb6SLionel Sambuc const value_type* data() const _NOEXCEPT 6814684ddb6SLionel Sambuc {return _VSTD::__to_raw_pointer(this->__begin_);} 6824684ddb6SLionel Sambuc 6834684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x); 6844684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 6854684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x); 6864684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_VARIADICS 6874684ddb6SLionel Sambuc template <class... _Args> 6884684ddb6SLionel Sambuc void emplace_back(_Args&&... __args); 6894684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_VARIADICS 6904684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 6914684ddb6SLionel Sambuc void pop_back(); 6924684ddb6SLionel Sambuc 6934684ddb6SLionel Sambuc iterator insert(const_iterator __position, const_reference __x); 6944684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 6954684ddb6SLionel Sambuc iterator insert(const_iterator __position, value_type&& __x); 6964684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_VARIADICS 6974684ddb6SLionel Sambuc template <class... _Args> 6984684ddb6SLionel Sambuc iterator emplace(const_iterator __position, _Args&&... __args); 6994684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_VARIADICS 7004684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 7014684ddb6SLionel Sambuc iterator insert(const_iterator __position, size_type __n, const_reference __x); 7024684ddb6SLionel Sambuc template <class _InputIterator> 7034684ddb6SLionel Sambuc typename enable_if 7044684ddb6SLionel Sambuc < 7054684ddb6SLionel Sambuc __is_input_iterator <_InputIterator>::value && 7064684ddb6SLionel Sambuc !__is_forward_iterator<_InputIterator>::value && 7074684ddb6SLionel Sambuc is_constructible< 7084684ddb6SLionel Sambuc value_type, 7094684ddb6SLionel Sambuc typename iterator_traits<_InputIterator>::reference>::value, 7104684ddb6SLionel Sambuc iterator 7114684ddb6SLionel Sambuc >::type 7124684ddb6SLionel Sambuc insert(const_iterator __position, _InputIterator __first, _InputIterator __last); 7134684ddb6SLionel Sambuc template <class _ForwardIterator> 7144684ddb6SLionel Sambuc typename enable_if 7154684ddb6SLionel Sambuc < 7164684ddb6SLionel Sambuc __is_forward_iterator<_ForwardIterator>::value && 7174684ddb6SLionel Sambuc is_constructible< 7184684ddb6SLionel Sambuc value_type, 7194684ddb6SLionel Sambuc typename iterator_traits<_ForwardIterator>::reference>::value, 7204684ddb6SLionel Sambuc iterator 7214684ddb6SLionel Sambuc >::type 7224684ddb6SLionel Sambuc insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last); 7234684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 7244684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 7254684ddb6SLionel Sambuc iterator insert(const_iterator __position, initializer_list<value_type> __il) 7264684ddb6SLionel Sambuc {return insert(__position, __il.begin(), __il.end());} 7274684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 7284684ddb6SLionel Sambuc 7294684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position); 7304684ddb6SLionel Sambuc iterator erase(const_iterator __first, const_iterator __last); 7314684ddb6SLionel Sambuc 7324684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 7334684ddb6SLionel Sambuc void clear() _NOEXCEPT 7344684ddb6SLionel Sambuc { 735*0a6a1f1dSLionel Sambuc size_type __old_size = size(); 7364684ddb6SLionel Sambuc __base::clear(); 737*0a6a1f1dSLionel Sambuc __annotate_shrink(__old_size); 7384684ddb6SLionel Sambuc __invalidate_all_iterators(); 7394684ddb6SLionel Sambuc } 7404684ddb6SLionel Sambuc 7414684ddb6SLionel Sambuc void resize(size_type __sz); 7424684ddb6SLionel Sambuc void resize(size_type __sz, const_reference __x); 7434684ddb6SLionel Sambuc 7444684ddb6SLionel Sambuc void swap(vector&) 745*0a6a1f1dSLionel Sambuc#if _LIBCPP_STD_VER >= 14 746*0a6a1f1dSLionel Sambuc _NOEXCEPT; 747*0a6a1f1dSLionel Sambuc#else 7484684ddb6SLionel Sambuc _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || 7494684ddb6SLionel Sambuc __is_nothrow_swappable<allocator_type>::value); 750*0a6a1f1dSLionel Sambuc#endif 7514684ddb6SLionel Sambuc 7524684ddb6SLionel Sambuc bool __invariants() const; 7534684ddb6SLionel Sambuc 7544684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2 7554684ddb6SLionel Sambuc 7564684ddb6SLionel Sambuc bool __dereferenceable(const const_iterator* __i) const; 7574684ddb6SLionel Sambuc bool __decrementable(const const_iterator* __i) const; 7584684ddb6SLionel Sambuc bool __addable(const const_iterator* __i, ptrdiff_t __n) const; 7594684ddb6SLionel Sambuc bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const; 7604684ddb6SLionel Sambuc 7614684ddb6SLionel Sambuc#endif // _LIBCPP_DEBUG_LEVEL >= 2 7624684ddb6SLionel Sambuc 7634684ddb6SLionel Sambucprivate: 7644684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators(); 7654684ddb6SLionel Sambuc void allocate(size_type __n); 7664684ddb6SLionel Sambuc void deallocate() _NOEXCEPT; 7674684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const; 7684684ddb6SLionel Sambuc void __construct_at_end(size_type __n); 7694684ddb6SLionel Sambuc void __construct_at_end(size_type __n, const_reference __x); 7704684ddb6SLionel Sambuc template <class _ForwardIterator> 7714684ddb6SLionel Sambuc typename enable_if 7724684ddb6SLionel Sambuc < 7734684ddb6SLionel Sambuc __is_forward_iterator<_ForwardIterator>::value, 7744684ddb6SLionel Sambuc void 7754684ddb6SLionel Sambuc >::type 776*0a6a1f1dSLionel Sambuc __construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n); 7774684ddb6SLionel Sambuc void __append(size_type __n); 7784684ddb6SLionel Sambuc void __append(size_type __n, const_reference __x); 7794684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 7804684ddb6SLionel Sambuc iterator __make_iter(pointer __p) _NOEXCEPT; 7814684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 7824684ddb6SLionel Sambuc const_iterator __make_iter(const_pointer __p) const _NOEXCEPT; 7834684ddb6SLionel Sambuc void __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v); 7844684ddb6SLionel Sambuc pointer __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p); 7854684ddb6SLionel Sambuc void __move_range(pointer __from_s, pointer __from_e, pointer __to); 7864684ddb6SLionel Sambuc void __move_assign(vector& __c, true_type) 7874684ddb6SLionel Sambuc _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); 788*0a6a1f1dSLionel Sambuc void __move_assign(vector& __c, false_type) 789*0a6a1f1dSLionel Sambuc _NOEXCEPT_(__alloc_traits::is_always_equal::value); 7904684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 7914684ddb6SLionel Sambuc void __destruct_at_end(pointer __new_last) _NOEXCEPT 7924684ddb6SLionel Sambuc { 7934684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2 7944684ddb6SLionel Sambuc __c_node* __c = __get_db()->__find_c_and_lock(this); 7954684ddb6SLionel Sambuc for (__i_node** __p = __c->end_; __p != __c->beg_; ) 7964684ddb6SLionel Sambuc { 7974684ddb6SLionel Sambuc --__p; 7984684ddb6SLionel Sambuc const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_); 7994684ddb6SLionel Sambuc if (__i->base() > __new_last) 8004684ddb6SLionel Sambuc { 8014684ddb6SLionel Sambuc (*__p)->__c_ = nullptr; 8024684ddb6SLionel Sambuc if (--__c->end_ != __p) 8034684ddb6SLionel Sambuc memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); 8044684ddb6SLionel Sambuc } 8054684ddb6SLionel Sambuc } 8064684ddb6SLionel Sambuc __get_db()->unlock(); 8074684ddb6SLionel Sambuc#endif 808*0a6a1f1dSLionel Sambuc size_type __old_size = size(); 8094684ddb6SLionel Sambuc __base::__destruct_at_end(__new_last); 810*0a6a1f1dSLionel Sambuc __annotate_shrink(__old_size); 8114684ddb6SLionel Sambuc } 8124684ddb6SLionel Sambuc template <class _Up> 8134684ddb6SLionel Sambuc void 8144684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 8154684ddb6SLionel Sambuc __push_back_slow_path(_Up&& __x); 8164684ddb6SLionel Sambuc#else 8174684ddb6SLionel Sambuc __push_back_slow_path(_Up& __x); 8184684ddb6SLionel Sambuc#endif 8194684ddb6SLionel Sambuc#if !defined(_LIBCPP_HAS_NO_VARIADICS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) 8204684ddb6SLionel Sambuc template <class... _Args> 8214684ddb6SLionel Sambuc void 8224684ddb6SLionel Sambuc __emplace_back_slow_path(_Args&&... __args); 8234684ddb6SLionel Sambuc#endif 824*0a6a1f1dSLionel Sambuc // The following functions are no-ops outside of AddressSanitizer mode. 825*0a6a1f1dSLionel Sambuc // We call annotatations only for the default Allocator because other allocators 826*0a6a1f1dSLionel Sambuc // may not meet the AddressSanitizer alignment constraints. 827*0a6a1f1dSLionel Sambuc // See the documentation for __sanitizer_annotate_contiguous_container for more details. 828*0a6a1f1dSLionel Sambuc void __annotate_contiguous_container 829*0a6a1f1dSLionel Sambuc (const void *__beg, const void *__end, const void *__old_mid, const void *__new_mid) const 830*0a6a1f1dSLionel Sambuc { 831*0a6a1f1dSLionel Sambuc#ifndef _LIBCPP_HAS_NO_ASAN 832*0a6a1f1dSLionel Sambuc if (__beg && is_same<allocator_type, __default_allocator_type>::value) 833*0a6a1f1dSLionel Sambuc __sanitizer_annotate_contiguous_container(__beg, __end, __old_mid, __new_mid); 834*0a6a1f1dSLionel Sambuc#endif 835*0a6a1f1dSLionel Sambuc } 836*0a6a1f1dSLionel Sambuc 837*0a6a1f1dSLionel Sambuc void __annotate_new(size_type __current_size) const 838*0a6a1f1dSLionel Sambuc { 839*0a6a1f1dSLionel Sambuc __annotate_contiguous_container(data(), data() + capacity(), 840*0a6a1f1dSLionel Sambuc data() + capacity(), data() + __current_size); 841*0a6a1f1dSLionel Sambuc } 842*0a6a1f1dSLionel Sambuc void __annotate_delete() const 843*0a6a1f1dSLionel Sambuc { 844*0a6a1f1dSLionel Sambuc __annotate_contiguous_container(data(), data() + capacity(), 845*0a6a1f1dSLionel Sambuc data() + size(), data() + capacity()); 846*0a6a1f1dSLionel Sambuc } 847*0a6a1f1dSLionel Sambuc void __annotate_increase(size_type __n) const 848*0a6a1f1dSLionel Sambuc { 849*0a6a1f1dSLionel Sambuc __annotate_contiguous_container(data(), data() + capacity(), 850*0a6a1f1dSLionel Sambuc data() + size(), data() + size() + __n); 851*0a6a1f1dSLionel Sambuc } 852*0a6a1f1dSLionel Sambuc void __annotate_shrink(size_type __old_size) const 853*0a6a1f1dSLionel Sambuc { 854*0a6a1f1dSLionel Sambuc __annotate_contiguous_container(data(), data() + capacity(), 855*0a6a1f1dSLionel Sambuc data() + __old_size, data() + size()); 856*0a6a1f1dSLionel Sambuc } 857*0a6a1f1dSLionel Sambuc#ifndef _LIBCPP_HAS_NO_ASAN 858*0a6a1f1dSLionel Sambuc // The annotation for size increase should happen before the actual increase, 859*0a6a1f1dSLionel Sambuc // but if an exception is thrown after that the annotation has to be undone. 860*0a6a1f1dSLionel Sambuc struct __RAII_IncreaseAnnotator { 861*0a6a1f1dSLionel Sambuc __RAII_IncreaseAnnotator(const vector &__v, size_type __n = 1) 862*0a6a1f1dSLionel Sambuc : __commit(false), __v(__v), __old_size(__v.size() + __n) { 863*0a6a1f1dSLionel Sambuc __v.__annotate_increase(__n); 864*0a6a1f1dSLionel Sambuc } 865*0a6a1f1dSLionel Sambuc void __done() { __commit = true; } 866*0a6a1f1dSLionel Sambuc ~__RAII_IncreaseAnnotator() { 867*0a6a1f1dSLionel Sambuc if (__commit) return; 868*0a6a1f1dSLionel Sambuc __v.__annotate_shrink(__old_size); 869*0a6a1f1dSLionel Sambuc } 870*0a6a1f1dSLionel Sambuc bool __commit; 871*0a6a1f1dSLionel Sambuc const vector &__v; 872*0a6a1f1dSLionel Sambuc size_type __old_size; 873*0a6a1f1dSLionel Sambuc }; 874*0a6a1f1dSLionel Sambuc#else 875*0a6a1f1dSLionel Sambuc struct __RAII_IncreaseAnnotator { 876*0a6a1f1dSLionel Sambuc inline __RAII_IncreaseAnnotator(const vector &, size_type __n = 1) {} 877*0a6a1f1dSLionel Sambuc inline void __done() {} 878*0a6a1f1dSLionel Sambuc }; 879*0a6a1f1dSLionel Sambuc#endif 880*0a6a1f1dSLionel Sambuc 8814684ddb6SLionel Sambuc}; 8824684ddb6SLionel Sambuc 8834684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 8844684ddb6SLionel Sambucvoid 8854684ddb6SLionel Sambucvector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v) 8864684ddb6SLionel Sambuc{ 887*0a6a1f1dSLionel Sambuc __annotate_delete(); 8884684ddb6SLionel Sambuc __alloc_traits::__construct_backward(this->__alloc(), this->__begin_, this->__end_, __v.__begin_); 8894684ddb6SLionel Sambuc _VSTD::swap(this->__begin_, __v.__begin_); 8904684ddb6SLionel Sambuc _VSTD::swap(this->__end_, __v.__end_); 8914684ddb6SLionel Sambuc _VSTD::swap(this->__end_cap(), __v.__end_cap()); 8924684ddb6SLionel Sambuc __v.__first_ = __v.__begin_; 893*0a6a1f1dSLionel Sambuc __annotate_new(size()); 8944684ddb6SLionel Sambuc __invalidate_all_iterators(); 8954684ddb6SLionel Sambuc} 8964684ddb6SLionel Sambuc 8974684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 8984684ddb6SLionel Sambuctypename vector<_Tp, _Allocator>::pointer 8994684ddb6SLionel Sambucvector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p) 9004684ddb6SLionel Sambuc{ 901*0a6a1f1dSLionel Sambuc __annotate_delete(); 9024684ddb6SLionel Sambuc pointer __r = __v.__begin_; 9034684ddb6SLionel Sambuc __alloc_traits::__construct_backward(this->__alloc(), this->__begin_, __p, __v.__begin_); 9044684ddb6SLionel Sambuc __alloc_traits::__construct_forward(this->__alloc(), __p, this->__end_, __v.__end_); 9054684ddb6SLionel Sambuc _VSTD::swap(this->__begin_, __v.__begin_); 9064684ddb6SLionel Sambuc _VSTD::swap(this->__end_, __v.__end_); 9074684ddb6SLionel Sambuc _VSTD::swap(this->__end_cap(), __v.__end_cap()); 9084684ddb6SLionel Sambuc __v.__first_ = __v.__begin_; 909*0a6a1f1dSLionel Sambuc __annotate_new(size()); 9104684ddb6SLionel Sambuc __invalidate_all_iterators(); 9114684ddb6SLionel Sambuc return __r; 9124684ddb6SLionel Sambuc} 9134684ddb6SLionel Sambuc 9144684ddb6SLionel Sambuc// Allocate space for __n objects 9154684ddb6SLionel Sambuc// throws length_error if __n > max_size() 9164684ddb6SLionel Sambuc// throws (probably bad_alloc) if memory run out 9174684ddb6SLionel Sambuc// Precondition: __begin_ == __end_ == __end_cap() == 0 9184684ddb6SLionel Sambuc// Precondition: __n > 0 9194684ddb6SLionel Sambuc// Postcondition: capacity() == __n 9204684ddb6SLionel Sambuc// Postcondition: size() == 0 9214684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 9224684ddb6SLionel Sambucvoid 9234684ddb6SLionel Sambucvector<_Tp, _Allocator>::allocate(size_type __n) 9244684ddb6SLionel Sambuc{ 9254684ddb6SLionel Sambuc if (__n > max_size()) 9264684ddb6SLionel Sambuc this->__throw_length_error(); 9274684ddb6SLionel Sambuc this->__begin_ = this->__end_ = __alloc_traits::allocate(this->__alloc(), __n); 9284684ddb6SLionel Sambuc this->__end_cap() = this->__begin_ + __n; 929*0a6a1f1dSLionel Sambuc __annotate_new(0); 9304684ddb6SLionel Sambuc} 9314684ddb6SLionel Sambuc 9324684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 9334684ddb6SLionel Sambucvoid 9344684ddb6SLionel Sambucvector<_Tp, _Allocator>::deallocate() _NOEXCEPT 9354684ddb6SLionel Sambuc{ 9364684ddb6SLionel Sambuc if (this->__begin_ != nullptr) 9374684ddb6SLionel Sambuc { 9384684ddb6SLionel Sambuc clear(); 9394684ddb6SLionel Sambuc __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity()); 9404684ddb6SLionel Sambuc this->__begin_ = this->__end_ = this->__end_cap() = nullptr; 9414684ddb6SLionel Sambuc } 9424684ddb6SLionel Sambuc} 9434684ddb6SLionel Sambuc 9444684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 9454684ddb6SLionel Sambuctypename vector<_Tp, _Allocator>::size_type 9464684ddb6SLionel Sambucvector<_Tp, _Allocator>::max_size() const _NOEXCEPT 9474684ddb6SLionel Sambuc{ 9484684ddb6SLionel Sambuc return _VSTD::min<size_type>(__alloc_traits::max_size(this->__alloc()), numeric_limits<size_type>::max() / 2); // end() >= begin(), always 9494684ddb6SLionel Sambuc} 9504684ddb6SLionel Sambuc 9514684ddb6SLionel Sambuc// Precondition: __new_size > capacity() 9524684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 9534684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 9544684ddb6SLionel Sambuctypename vector<_Tp, _Allocator>::size_type 9554684ddb6SLionel Sambucvector<_Tp, _Allocator>::__recommend(size_type __new_size) const 9564684ddb6SLionel Sambuc{ 9574684ddb6SLionel Sambuc const size_type __ms = max_size(); 9584684ddb6SLionel Sambuc if (__new_size > __ms) 9594684ddb6SLionel Sambuc this->__throw_length_error(); 9604684ddb6SLionel Sambuc const size_type __cap = capacity(); 9614684ddb6SLionel Sambuc if (__cap >= __ms / 2) 9624684ddb6SLionel Sambuc return __ms; 9634684ddb6SLionel Sambuc return _VSTD::max<size_type>(2*__cap, __new_size); 9644684ddb6SLionel Sambuc} 9654684ddb6SLionel Sambuc 9664684ddb6SLionel Sambuc// Default constructs __n objects starting at __end_ 9674684ddb6SLionel Sambuc// throws if construction throws 9684684ddb6SLionel Sambuc// Precondition: __n > 0 9694684ddb6SLionel Sambuc// Precondition: size() + __n <= capacity() 9704684ddb6SLionel Sambuc// Postcondition: size() == size() + __n 9714684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 9724684ddb6SLionel Sambucvoid 9734684ddb6SLionel Sambucvector<_Tp, _Allocator>::__construct_at_end(size_type __n) 9744684ddb6SLionel Sambuc{ 9754684ddb6SLionel Sambuc allocator_type& __a = this->__alloc(); 9764684ddb6SLionel Sambuc do 9774684ddb6SLionel Sambuc { 978*0a6a1f1dSLionel Sambuc __RAII_IncreaseAnnotator __annotator(*this); 9794684ddb6SLionel Sambuc __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_)); 9804684ddb6SLionel Sambuc ++this->__end_; 9814684ddb6SLionel Sambuc --__n; 982*0a6a1f1dSLionel Sambuc __annotator.__done(); 9834684ddb6SLionel Sambuc } while (__n > 0); 9844684ddb6SLionel Sambuc} 9854684ddb6SLionel Sambuc 9864684ddb6SLionel Sambuc// Copy constructs __n objects starting at __end_ from __x 9874684ddb6SLionel Sambuc// throws if construction throws 9884684ddb6SLionel Sambuc// Precondition: __n > 0 9894684ddb6SLionel Sambuc// Precondition: size() + __n <= capacity() 9904684ddb6SLionel Sambuc// Postcondition: size() == old size() + __n 9914684ddb6SLionel Sambuc// Postcondition: [i] == __x for all i in [size() - __n, __n) 9924684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 9934684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 9944684ddb6SLionel Sambucvoid 9954684ddb6SLionel Sambucvector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x) 9964684ddb6SLionel Sambuc{ 9974684ddb6SLionel Sambuc allocator_type& __a = this->__alloc(); 9984684ddb6SLionel Sambuc do 9994684ddb6SLionel Sambuc { 1000*0a6a1f1dSLionel Sambuc __RAII_IncreaseAnnotator __annotator(*this); 10014684ddb6SLionel Sambuc __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), __x); 10024684ddb6SLionel Sambuc ++this->__end_; 10034684ddb6SLionel Sambuc --__n; 1004*0a6a1f1dSLionel Sambuc __annotator.__done(); 10054684ddb6SLionel Sambuc } while (__n > 0); 10064684ddb6SLionel Sambuc} 10074684ddb6SLionel Sambuc 10084684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 10094684ddb6SLionel Sambuctemplate <class _ForwardIterator> 10104684ddb6SLionel Sambuctypename enable_if 10114684ddb6SLionel Sambuc< 10124684ddb6SLionel Sambuc __is_forward_iterator<_ForwardIterator>::value, 10134684ddb6SLionel Sambuc void 10144684ddb6SLionel Sambuc>::type 1015*0a6a1f1dSLionel Sambucvector<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n) 10164684ddb6SLionel Sambuc{ 10174684ddb6SLionel Sambuc allocator_type& __a = this->__alloc(); 1018*0a6a1f1dSLionel Sambuc __RAII_IncreaseAnnotator __annotator(*this, __n); 1019*0a6a1f1dSLionel Sambuc __alloc_traits::__construct_range_forward(__a, __first, __last, this->__end_); 1020*0a6a1f1dSLionel Sambuc __annotator.__done(); 10214684ddb6SLionel Sambuc} 10224684ddb6SLionel Sambuc 10234684ddb6SLionel Sambuc// Default constructs __n objects starting at __end_ 10244684ddb6SLionel Sambuc// throws if construction throws 10254684ddb6SLionel Sambuc// Postcondition: size() == size() + __n 10264684ddb6SLionel Sambuc// Exception safety: strong. 10274684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 10284684ddb6SLionel Sambucvoid 10294684ddb6SLionel Sambucvector<_Tp, _Allocator>::__append(size_type __n) 10304684ddb6SLionel Sambuc{ 10314684ddb6SLionel Sambuc if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n) 10324684ddb6SLionel Sambuc this->__construct_at_end(__n); 10334684ddb6SLionel Sambuc else 10344684ddb6SLionel Sambuc { 10354684ddb6SLionel Sambuc allocator_type& __a = this->__alloc(); 10364684ddb6SLionel Sambuc __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a); 10374684ddb6SLionel Sambuc __v.__construct_at_end(__n); 10384684ddb6SLionel Sambuc __swap_out_circular_buffer(__v); 10394684ddb6SLionel Sambuc } 10404684ddb6SLionel Sambuc} 10414684ddb6SLionel Sambuc 10424684ddb6SLionel Sambuc// Default constructs __n objects starting at __end_ 10434684ddb6SLionel Sambuc// throws if construction throws 10444684ddb6SLionel Sambuc// Postcondition: size() == size() + __n 10454684ddb6SLionel Sambuc// Exception safety: strong. 10464684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 10474684ddb6SLionel Sambucvoid 10484684ddb6SLionel Sambucvector<_Tp, _Allocator>::__append(size_type __n, const_reference __x) 10494684ddb6SLionel Sambuc{ 10504684ddb6SLionel Sambuc if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n) 10514684ddb6SLionel Sambuc this->__construct_at_end(__n, __x); 10524684ddb6SLionel Sambuc else 10534684ddb6SLionel Sambuc { 10544684ddb6SLionel Sambuc allocator_type& __a = this->__alloc(); 10554684ddb6SLionel Sambuc __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a); 10564684ddb6SLionel Sambuc __v.__construct_at_end(__n, __x); 10574684ddb6SLionel Sambuc __swap_out_circular_buffer(__v); 10584684ddb6SLionel Sambuc } 10594684ddb6SLionel Sambuc} 10604684ddb6SLionel Sambuc 10614684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 10624684ddb6SLionel Sambucvector<_Tp, _Allocator>::vector(size_type __n) 10634684ddb6SLionel Sambuc{ 10644684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2 10654684ddb6SLionel Sambuc __get_db()->__insert_c(this); 10664684ddb6SLionel Sambuc#endif 10674684ddb6SLionel Sambuc if (__n > 0) 10684684ddb6SLionel Sambuc { 10694684ddb6SLionel Sambuc allocate(__n); 10704684ddb6SLionel Sambuc __construct_at_end(__n); 10714684ddb6SLionel Sambuc } 10724684ddb6SLionel Sambuc} 10734684ddb6SLionel Sambuc 10744684ddb6SLionel Sambuc#if _LIBCPP_STD_VER > 11 10754684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 10764684ddb6SLionel Sambucvector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a) 10774684ddb6SLionel Sambuc : __base(__a) 10784684ddb6SLionel Sambuc{ 10794684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2 10804684ddb6SLionel Sambuc __get_db()->__insert_c(this); 10814684ddb6SLionel Sambuc#endif 10824684ddb6SLionel Sambuc if (__n > 0) 10834684ddb6SLionel Sambuc { 10844684ddb6SLionel Sambuc allocate(__n); 10854684ddb6SLionel Sambuc __construct_at_end(__n); 10864684ddb6SLionel Sambuc } 10874684ddb6SLionel Sambuc} 10884684ddb6SLionel Sambuc#endif 10894684ddb6SLionel Sambuc 10904684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 10914684ddb6SLionel Sambucvector<_Tp, _Allocator>::vector(size_type __n, const_reference __x) 10924684ddb6SLionel Sambuc{ 10934684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2 10944684ddb6SLionel Sambuc __get_db()->__insert_c(this); 10954684ddb6SLionel Sambuc#endif 10964684ddb6SLionel Sambuc if (__n > 0) 10974684ddb6SLionel Sambuc { 10984684ddb6SLionel Sambuc allocate(__n); 10994684ddb6SLionel Sambuc __construct_at_end(__n, __x); 11004684ddb6SLionel Sambuc } 11014684ddb6SLionel Sambuc} 11024684ddb6SLionel Sambuc 11034684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 11044684ddb6SLionel Sambucvector<_Tp, _Allocator>::vector(size_type __n, const_reference __x, const allocator_type& __a) 11054684ddb6SLionel Sambuc : __base(__a) 11064684ddb6SLionel Sambuc{ 11074684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2 11084684ddb6SLionel Sambuc __get_db()->__insert_c(this); 11094684ddb6SLionel Sambuc#endif 11104684ddb6SLionel Sambuc if (__n > 0) 11114684ddb6SLionel Sambuc { 11124684ddb6SLionel Sambuc allocate(__n); 11134684ddb6SLionel Sambuc __construct_at_end(__n, __x); 11144684ddb6SLionel Sambuc } 11154684ddb6SLionel Sambuc} 11164684ddb6SLionel Sambuc 11174684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 11184684ddb6SLionel Sambuctemplate <class _InputIterator> 11194684ddb6SLionel Sambucvector<_Tp, _Allocator>::vector(_InputIterator __first, 11204684ddb6SLionel Sambuc typename enable_if<__is_input_iterator <_InputIterator>::value && 11214684ddb6SLionel Sambuc !__is_forward_iterator<_InputIterator>::value && 11224684ddb6SLionel Sambuc is_constructible< 11234684ddb6SLionel Sambuc value_type, 11244684ddb6SLionel Sambuc typename iterator_traits<_InputIterator>::reference>::value, 11254684ddb6SLionel Sambuc _InputIterator>::type __last) 11264684ddb6SLionel Sambuc{ 11274684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2 11284684ddb6SLionel Sambuc __get_db()->__insert_c(this); 11294684ddb6SLionel Sambuc#endif 11304684ddb6SLionel Sambuc for (; __first != __last; ++__first) 11314684ddb6SLionel Sambuc push_back(*__first); 11324684ddb6SLionel Sambuc} 11334684ddb6SLionel Sambuc 11344684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 11354684ddb6SLionel Sambuctemplate <class _InputIterator> 11364684ddb6SLionel Sambucvector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, 11374684ddb6SLionel Sambuc typename enable_if<__is_input_iterator <_InputIterator>::value && 11384684ddb6SLionel Sambuc !__is_forward_iterator<_InputIterator>::value && 11394684ddb6SLionel Sambuc is_constructible< 11404684ddb6SLionel Sambuc value_type, 11414684ddb6SLionel Sambuc typename iterator_traits<_InputIterator>::reference>::value>::type*) 11424684ddb6SLionel Sambuc : __base(__a) 11434684ddb6SLionel Sambuc{ 11444684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2 11454684ddb6SLionel Sambuc __get_db()->__insert_c(this); 11464684ddb6SLionel Sambuc#endif 11474684ddb6SLionel Sambuc for (; __first != __last; ++__first) 11484684ddb6SLionel Sambuc push_back(*__first); 11494684ddb6SLionel Sambuc} 11504684ddb6SLionel Sambuc 11514684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 11524684ddb6SLionel Sambuctemplate <class _ForwardIterator> 11534684ddb6SLionel Sambucvector<_Tp, _Allocator>::vector(_ForwardIterator __first, 11544684ddb6SLionel Sambuc typename enable_if<__is_forward_iterator<_ForwardIterator>::value && 11554684ddb6SLionel Sambuc is_constructible< 11564684ddb6SLionel Sambuc value_type, 11574684ddb6SLionel Sambuc typename iterator_traits<_ForwardIterator>::reference>::value, 11584684ddb6SLionel Sambuc _ForwardIterator>::type __last) 11594684ddb6SLionel Sambuc{ 11604684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2 11614684ddb6SLionel Sambuc __get_db()->__insert_c(this); 11624684ddb6SLionel Sambuc#endif 11634684ddb6SLionel Sambuc size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); 11644684ddb6SLionel Sambuc if (__n > 0) 11654684ddb6SLionel Sambuc { 11664684ddb6SLionel Sambuc allocate(__n); 1167*0a6a1f1dSLionel Sambuc __construct_at_end(__first, __last, __n); 11684684ddb6SLionel Sambuc } 11694684ddb6SLionel Sambuc} 11704684ddb6SLionel Sambuc 11714684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 11724684ddb6SLionel Sambuctemplate <class _ForwardIterator> 11734684ddb6SLionel Sambucvector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, 11744684ddb6SLionel Sambuc typename enable_if<__is_forward_iterator<_ForwardIterator>::value && 11754684ddb6SLionel Sambuc is_constructible< 11764684ddb6SLionel Sambuc value_type, 11774684ddb6SLionel Sambuc typename iterator_traits<_ForwardIterator>::reference>::value>::type*) 11784684ddb6SLionel Sambuc : __base(__a) 11794684ddb6SLionel Sambuc{ 11804684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2 11814684ddb6SLionel Sambuc __get_db()->__insert_c(this); 11824684ddb6SLionel Sambuc#endif 11834684ddb6SLionel Sambuc size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); 11844684ddb6SLionel Sambuc if (__n > 0) 11854684ddb6SLionel Sambuc { 11864684ddb6SLionel Sambuc allocate(__n); 1187*0a6a1f1dSLionel Sambuc __construct_at_end(__first, __last, __n); 11884684ddb6SLionel Sambuc } 11894684ddb6SLionel Sambuc} 11904684ddb6SLionel Sambuc 11914684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 11924684ddb6SLionel Sambucvector<_Tp, _Allocator>::vector(const vector& __x) 11934684ddb6SLionel Sambuc : __base(__alloc_traits::select_on_container_copy_construction(__x.__alloc())) 11944684ddb6SLionel Sambuc{ 11954684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2 11964684ddb6SLionel Sambuc __get_db()->__insert_c(this); 11974684ddb6SLionel Sambuc#endif 11984684ddb6SLionel Sambuc size_type __n = __x.size(); 11994684ddb6SLionel Sambuc if (__n > 0) 12004684ddb6SLionel Sambuc { 12014684ddb6SLionel Sambuc allocate(__n); 1202*0a6a1f1dSLionel Sambuc __construct_at_end(__x.__begin_, __x.__end_, __n); 12034684ddb6SLionel Sambuc } 12044684ddb6SLionel Sambuc} 12054684ddb6SLionel Sambuc 12064684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 12074684ddb6SLionel Sambucvector<_Tp, _Allocator>::vector(const vector& __x, const allocator_type& __a) 12084684ddb6SLionel Sambuc : __base(__a) 12094684ddb6SLionel Sambuc{ 12104684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2 12114684ddb6SLionel Sambuc __get_db()->__insert_c(this); 12124684ddb6SLionel Sambuc#endif 12134684ddb6SLionel Sambuc size_type __n = __x.size(); 12144684ddb6SLionel Sambuc if (__n > 0) 12154684ddb6SLionel Sambuc { 12164684ddb6SLionel Sambuc allocate(__n); 1217*0a6a1f1dSLionel Sambuc __construct_at_end(__x.__begin_, __x.__end_, __n); 12184684ddb6SLionel Sambuc } 12194684ddb6SLionel Sambuc} 12204684ddb6SLionel Sambuc 12214684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 12224684ddb6SLionel Sambuc 12234684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 12244684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 12254684ddb6SLionel Sambucvector<_Tp, _Allocator>::vector(vector&& __x) 1226*0a6a1f1dSLionel Sambuc#if _LIBCPP_STD_VER > 14 1227*0a6a1f1dSLionel Sambuc _NOEXCEPT 1228*0a6a1f1dSLionel Sambuc#else 12294684ddb6SLionel Sambuc _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) 1230*0a6a1f1dSLionel Sambuc#endif 12314684ddb6SLionel Sambuc : __base(_VSTD::move(__x.__alloc())) 12324684ddb6SLionel Sambuc{ 12334684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2 12344684ddb6SLionel Sambuc __get_db()->__insert_c(this); 12354684ddb6SLionel Sambuc __get_db()->swap(this, &__x); 12364684ddb6SLionel Sambuc#endif 12374684ddb6SLionel Sambuc this->__begin_ = __x.__begin_; 12384684ddb6SLionel Sambuc this->__end_ = __x.__end_; 12394684ddb6SLionel Sambuc this->__end_cap() = __x.__end_cap(); 12404684ddb6SLionel Sambuc __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr; 12414684ddb6SLionel Sambuc} 12424684ddb6SLionel Sambuc 12434684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 12444684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 12454684ddb6SLionel Sambucvector<_Tp, _Allocator>::vector(vector&& __x, const allocator_type& __a) 12464684ddb6SLionel Sambuc : __base(__a) 12474684ddb6SLionel Sambuc{ 12484684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2 12494684ddb6SLionel Sambuc __get_db()->__insert_c(this); 12504684ddb6SLionel Sambuc#endif 12514684ddb6SLionel Sambuc if (__a == __x.__alloc()) 12524684ddb6SLionel Sambuc { 12534684ddb6SLionel Sambuc this->__begin_ = __x.__begin_; 12544684ddb6SLionel Sambuc this->__end_ = __x.__end_; 12554684ddb6SLionel Sambuc this->__end_cap() = __x.__end_cap(); 12564684ddb6SLionel Sambuc __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr; 12574684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2 12584684ddb6SLionel Sambuc __get_db()->swap(this, &__x); 12594684ddb6SLionel Sambuc#endif 12604684ddb6SLionel Sambuc } 12614684ddb6SLionel Sambuc else 12624684ddb6SLionel Sambuc { 12634684ddb6SLionel Sambuc typedef move_iterator<iterator> _Ip; 12644684ddb6SLionel Sambuc assign(_Ip(__x.begin()), _Ip(__x.end())); 12654684ddb6SLionel Sambuc } 12664684ddb6SLionel Sambuc} 12674684ddb6SLionel Sambuc 12684684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 12694684ddb6SLionel Sambuc 12704684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 12714684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 12724684ddb6SLionel Sambucvector<_Tp, _Allocator>::vector(initializer_list<value_type> __il) 12734684ddb6SLionel Sambuc{ 12744684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2 12754684ddb6SLionel Sambuc __get_db()->__insert_c(this); 12764684ddb6SLionel Sambuc#endif 12774684ddb6SLionel Sambuc if (__il.size() > 0) 12784684ddb6SLionel Sambuc { 12794684ddb6SLionel Sambuc allocate(__il.size()); 1280*0a6a1f1dSLionel Sambuc __construct_at_end(__il.begin(), __il.end(), __il.size()); 12814684ddb6SLionel Sambuc } 12824684ddb6SLionel Sambuc} 12834684ddb6SLionel Sambuc 12844684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 12854684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 12864684ddb6SLionel Sambucvector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a) 12874684ddb6SLionel Sambuc : __base(__a) 12884684ddb6SLionel Sambuc{ 12894684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2 12904684ddb6SLionel Sambuc __get_db()->__insert_c(this); 12914684ddb6SLionel Sambuc#endif 12924684ddb6SLionel Sambuc if (__il.size() > 0) 12934684ddb6SLionel Sambuc { 12944684ddb6SLionel Sambuc allocate(__il.size()); 1295*0a6a1f1dSLionel Sambuc __construct_at_end(__il.begin(), __il.end(), __il.size()); 12964684ddb6SLionel Sambuc } 12974684ddb6SLionel Sambuc} 12984684ddb6SLionel Sambuc 12994684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 13004684ddb6SLionel Sambuc 13014684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 13024684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 13034684ddb6SLionel Sambucvector<_Tp, _Allocator>& 13044684ddb6SLionel Sambucvector<_Tp, _Allocator>::operator=(vector&& __x) 1305*0a6a1f1dSLionel Sambuc _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) 13064684ddb6SLionel Sambuc{ 13074684ddb6SLionel Sambuc __move_assign(__x, integral_constant<bool, 13084684ddb6SLionel Sambuc __alloc_traits::propagate_on_container_move_assignment::value>()); 13094684ddb6SLionel Sambuc return *this; 13104684ddb6SLionel Sambuc} 13114684ddb6SLionel Sambuc 13124684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 13134684ddb6SLionel Sambucvoid 13144684ddb6SLionel Sambucvector<_Tp, _Allocator>::__move_assign(vector& __c, false_type) 1315*0a6a1f1dSLionel Sambuc _NOEXCEPT_(__alloc_traits::is_always_equal::value) 13164684ddb6SLionel Sambuc{ 13174684ddb6SLionel Sambuc if (__base::__alloc() != __c.__alloc()) 13184684ddb6SLionel Sambuc { 13194684ddb6SLionel Sambuc typedef move_iterator<iterator> _Ip; 13204684ddb6SLionel Sambuc assign(_Ip(__c.begin()), _Ip(__c.end())); 13214684ddb6SLionel Sambuc } 13224684ddb6SLionel Sambuc else 13234684ddb6SLionel Sambuc __move_assign(__c, true_type()); 13244684ddb6SLionel Sambuc} 13254684ddb6SLionel Sambuc 13264684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 13274684ddb6SLionel Sambucvoid 13284684ddb6SLionel Sambucvector<_Tp, _Allocator>::__move_assign(vector& __c, true_type) 13294684ddb6SLionel Sambuc _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) 13304684ddb6SLionel Sambuc{ 13314684ddb6SLionel Sambuc deallocate(); 1332*0a6a1f1dSLionel Sambuc __base::__move_assign_alloc(__c); // this can throw 13334684ddb6SLionel Sambuc this->__begin_ = __c.__begin_; 13344684ddb6SLionel Sambuc this->__end_ = __c.__end_; 13354684ddb6SLionel Sambuc this->__end_cap() = __c.__end_cap(); 13364684ddb6SLionel Sambuc __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr; 13374684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2 13384684ddb6SLionel Sambuc __get_db()->swap(this, &__c); 13394684ddb6SLionel Sambuc#endif 13404684ddb6SLionel Sambuc} 13414684ddb6SLionel Sambuc 13424684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 13434684ddb6SLionel Sambuc 13444684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 13454684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 13464684ddb6SLionel Sambucvector<_Tp, _Allocator>& 13474684ddb6SLionel Sambucvector<_Tp, _Allocator>::operator=(const vector& __x) 13484684ddb6SLionel Sambuc{ 13494684ddb6SLionel Sambuc if (this != &__x) 13504684ddb6SLionel Sambuc { 13514684ddb6SLionel Sambuc __base::__copy_assign_alloc(__x); 13524684ddb6SLionel Sambuc assign(__x.__begin_, __x.__end_); 13534684ddb6SLionel Sambuc } 13544684ddb6SLionel Sambuc return *this; 13554684ddb6SLionel Sambuc} 13564684ddb6SLionel Sambuc 13574684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 13584684ddb6SLionel Sambuctemplate <class _InputIterator> 13594684ddb6SLionel Sambuctypename enable_if 13604684ddb6SLionel Sambuc< 13614684ddb6SLionel Sambuc __is_input_iterator <_InputIterator>::value && 13624684ddb6SLionel Sambuc !__is_forward_iterator<_InputIterator>::value && 13634684ddb6SLionel Sambuc is_constructible< 13644684ddb6SLionel Sambuc _Tp, 13654684ddb6SLionel Sambuc typename iterator_traits<_InputIterator>::reference>::value, 13664684ddb6SLionel Sambuc void 13674684ddb6SLionel Sambuc>::type 13684684ddb6SLionel Sambucvector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last) 13694684ddb6SLionel Sambuc{ 13704684ddb6SLionel Sambuc clear(); 13714684ddb6SLionel Sambuc for (; __first != __last; ++__first) 13724684ddb6SLionel Sambuc push_back(*__first); 13734684ddb6SLionel Sambuc} 13744684ddb6SLionel Sambuc 13754684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 13764684ddb6SLionel Sambuctemplate <class _ForwardIterator> 13774684ddb6SLionel Sambuctypename enable_if 13784684ddb6SLionel Sambuc< 13794684ddb6SLionel Sambuc __is_forward_iterator<_ForwardIterator>::value && 13804684ddb6SLionel Sambuc is_constructible< 13814684ddb6SLionel Sambuc _Tp, 13824684ddb6SLionel Sambuc typename iterator_traits<_ForwardIterator>::reference>::value, 13834684ddb6SLionel Sambuc void 13844684ddb6SLionel Sambuc>::type 13854684ddb6SLionel Sambucvector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) 13864684ddb6SLionel Sambuc{ 1387*0a6a1f1dSLionel Sambuc size_type __new_size = static_cast<size_type>(_VSTD::distance(__first, __last)); 1388*0a6a1f1dSLionel Sambuc if (__new_size <= capacity()) 13894684ddb6SLionel Sambuc { 13904684ddb6SLionel Sambuc _ForwardIterator __mid = __last; 13914684ddb6SLionel Sambuc bool __growing = false; 1392*0a6a1f1dSLionel Sambuc if (__new_size > size()) 13934684ddb6SLionel Sambuc { 13944684ddb6SLionel Sambuc __growing = true; 13954684ddb6SLionel Sambuc __mid = __first; 13964684ddb6SLionel Sambuc _VSTD::advance(__mid, size()); 13974684ddb6SLionel Sambuc } 13984684ddb6SLionel Sambuc pointer __m = _VSTD::copy(__first, __mid, this->__begin_); 13994684ddb6SLionel Sambuc if (__growing) 1400*0a6a1f1dSLionel Sambuc __construct_at_end(__mid, __last, __new_size - size()); 14014684ddb6SLionel Sambuc else 14024684ddb6SLionel Sambuc this->__destruct_at_end(__m); 14034684ddb6SLionel Sambuc } 14044684ddb6SLionel Sambuc else 14054684ddb6SLionel Sambuc { 14064684ddb6SLionel Sambuc deallocate(); 1407*0a6a1f1dSLionel Sambuc allocate(__recommend(__new_size)); 1408*0a6a1f1dSLionel Sambuc __construct_at_end(__first, __last, __new_size); 14094684ddb6SLionel Sambuc } 14104684ddb6SLionel Sambuc} 14114684ddb6SLionel Sambuc 14124684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 14134684ddb6SLionel Sambucvoid 14144684ddb6SLionel Sambucvector<_Tp, _Allocator>::assign(size_type __n, const_reference __u) 14154684ddb6SLionel Sambuc{ 14164684ddb6SLionel Sambuc if (__n <= capacity()) 14174684ddb6SLionel Sambuc { 14184684ddb6SLionel Sambuc size_type __s = size(); 14194684ddb6SLionel Sambuc _VSTD::fill_n(this->__begin_, _VSTD::min(__n, __s), __u); 14204684ddb6SLionel Sambuc if (__n > __s) 14214684ddb6SLionel Sambuc __construct_at_end(__n - __s, __u); 14224684ddb6SLionel Sambuc else 14234684ddb6SLionel Sambuc this->__destruct_at_end(this->__begin_ + __n); 14244684ddb6SLionel Sambuc } 14254684ddb6SLionel Sambuc else 14264684ddb6SLionel Sambuc { 14274684ddb6SLionel Sambuc deallocate(); 14284684ddb6SLionel Sambuc allocate(__recommend(static_cast<size_type>(__n))); 14294684ddb6SLionel Sambuc __construct_at_end(__n, __u); 14304684ddb6SLionel Sambuc } 14314684ddb6SLionel Sambuc} 14324684ddb6SLionel Sambuc 14334684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 14344684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 14354684ddb6SLionel Sambuctypename vector<_Tp, _Allocator>::iterator 14364684ddb6SLionel Sambucvector<_Tp, _Allocator>::__make_iter(pointer __p) _NOEXCEPT 14374684ddb6SLionel Sambuc{ 14384684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2 14394684ddb6SLionel Sambuc return iterator(this, __p); 14404684ddb6SLionel Sambuc#else 14414684ddb6SLionel Sambuc return iterator(__p); 14424684ddb6SLionel Sambuc#endif 14434684ddb6SLionel Sambuc} 14444684ddb6SLionel Sambuc 14454684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 14464684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 14474684ddb6SLionel Sambuctypename vector<_Tp, _Allocator>::const_iterator 14484684ddb6SLionel Sambucvector<_Tp, _Allocator>::__make_iter(const_pointer __p) const _NOEXCEPT 14494684ddb6SLionel Sambuc{ 14504684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2 14514684ddb6SLionel Sambuc return const_iterator(this, __p); 14524684ddb6SLionel Sambuc#else 14534684ddb6SLionel Sambuc return const_iterator(__p); 14544684ddb6SLionel Sambuc#endif 14554684ddb6SLionel Sambuc} 14564684ddb6SLionel Sambuc 14574684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 14584684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 14594684ddb6SLionel Sambuctypename vector<_Tp, _Allocator>::iterator 14604684ddb6SLionel Sambucvector<_Tp, _Allocator>::begin() _NOEXCEPT 14614684ddb6SLionel Sambuc{ 14624684ddb6SLionel Sambuc return __make_iter(this->__begin_); 14634684ddb6SLionel Sambuc} 14644684ddb6SLionel Sambuc 14654684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 14664684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 14674684ddb6SLionel Sambuctypename vector<_Tp, _Allocator>::const_iterator 14684684ddb6SLionel Sambucvector<_Tp, _Allocator>::begin() const _NOEXCEPT 14694684ddb6SLionel Sambuc{ 14704684ddb6SLionel Sambuc return __make_iter(this->__begin_); 14714684ddb6SLionel Sambuc} 14724684ddb6SLionel Sambuc 14734684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 14744684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 14754684ddb6SLionel Sambuctypename vector<_Tp, _Allocator>::iterator 14764684ddb6SLionel Sambucvector<_Tp, _Allocator>::end() _NOEXCEPT 14774684ddb6SLionel Sambuc{ 14784684ddb6SLionel Sambuc return __make_iter(this->__end_); 14794684ddb6SLionel Sambuc} 14804684ddb6SLionel Sambuc 14814684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 14824684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 14834684ddb6SLionel Sambuctypename vector<_Tp, _Allocator>::const_iterator 14844684ddb6SLionel Sambucvector<_Tp, _Allocator>::end() const _NOEXCEPT 14854684ddb6SLionel Sambuc{ 14864684ddb6SLionel Sambuc return __make_iter(this->__end_); 14874684ddb6SLionel Sambuc} 14884684ddb6SLionel Sambuc 14894684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 14904684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 14914684ddb6SLionel Sambuctypename vector<_Tp, _Allocator>::reference 14924684ddb6SLionel Sambucvector<_Tp, _Allocator>::operator[](size_type __n) 14934684ddb6SLionel Sambuc{ 14944684ddb6SLionel Sambuc _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds"); 14954684ddb6SLionel Sambuc return this->__begin_[__n]; 14964684ddb6SLionel Sambuc} 14974684ddb6SLionel Sambuc 14984684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 14994684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 15004684ddb6SLionel Sambuctypename vector<_Tp, _Allocator>::const_reference 15014684ddb6SLionel Sambucvector<_Tp, _Allocator>::operator[](size_type __n) const 15024684ddb6SLionel Sambuc{ 15034684ddb6SLionel Sambuc _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds"); 15044684ddb6SLionel Sambuc return this->__begin_[__n]; 15054684ddb6SLionel Sambuc} 15064684ddb6SLionel Sambuc 15074684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 15084684ddb6SLionel Sambuctypename vector<_Tp, _Allocator>::reference 15094684ddb6SLionel Sambucvector<_Tp, _Allocator>::at(size_type __n) 15104684ddb6SLionel Sambuc{ 15114684ddb6SLionel Sambuc if (__n >= size()) 15124684ddb6SLionel Sambuc this->__throw_out_of_range(); 15134684ddb6SLionel Sambuc return this->__begin_[__n]; 15144684ddb6SLionel Sambuc} 15154684ddb6SLionel Sambuc 15164684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 15174684ddb6SLionel Sambuctypename vector<_Tp, _Allocator>::const_reference 15184684ddb6SLionel Sambucvector<_Tp, _Allocator>::at(size_type __n) const 15194684ddb6SLionel Sambuc{ 15204684ddb6SLionel Sambuc if (__n >= size()) 15214684ddb6SLionel Sambuc this->__throw_out_of_range(); 15224684ddb6SLionel Sambuc return this->__begin_[__n]; 15234684ddb6SLionel Sambuc} 15244684ddb6SLionel Sambuc 15254684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 15264684ddb6SLionel Sambucvoid 15274684ddb6SLionel Sambucvector<_Tp, _Allocator>::reserve(size_type __n) 15284684ddb6SLionel Sambuc{ 15294684ddb6SLionel Sambuc if (__n > capacity()) 15304684ddb6SLionel Sambuc { 15314684ddb6SLionel Sambuc allocator_type& __a = this->__alloc(); 15324684ddb6SLionel Sambuc __split_buffer<value_type, allocator_type&> __v(__n, size(), __a); 15334684ddb6SLionel Sambuc __swap_out_circular_buffer(__v); 15344684ddb6SLionel Sambuc } 15354684ddb6SLionel Sambuc} 15364684ddb6SLionel Sambuc 15374684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 15384684ddb6SLionel Sambucvoid 15394684ddb6SLionel Sambucvector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT 15404684ddb6SLionel Sambuc{ 15414684ddb6SLionel Sambuc if (capacity() > size()) 15424684ddb6SLionel Sambuc { 15434684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 15444684ddb6SLionel Sambuc try 15454684ddb6SLionel Sambuc { 15464684ddb6SLionel Sambuc#endif // _LIBCPP_NO_EXCEPTIONS 15474684ddb6SLionel Sambuc allocator_type& __a = this->__alloc(); 15484684ddb6SLionel Sambuc __split_buffer<value_type, allocator_type&> __v(size(), size(), __a); 15494684ddb6SLionel Sambuc __swap_out_circular_buffer(__v); 15504684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 15514684ddb6SLionel Sambuc } 15524684ddb6SLionel Sambuc catch (...) 15534684ddb6SLionel Sambuc { 15544684ddb6SLionel Sambuc } 15554684ddb6SLionel Sambuc#endif // _LIBCPP_NO_EXCEPTIONS 15564684ddb6SLionel Sambuc } 15574684ddb6SLionel Sambuc} 15584684ddb6SLionel Sambuc 15594684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 15604684ddb6SLionel Sambuctemplate <class _Up> 15614684ddb6SLionel Sambucvoid 15624684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 15634684ddb6SLionel Sambucvector<_Tp, _Allocator>::__push_back_slow_path(_Up&& __x) 15644684ddb6SLionel Sambuc#else 15654684ddb6SLionel Sambucvector<_Tp, _Allocator>::__push_back_slow_path(_Up& __x) 15664684ddb6SLionel Sambuc#endif 15674684ddb6SLionel Sambuc{ 15684684ddb6SLionel Sambuc allocator_type& __a = this->__alloc(); 15694684ddb6SLionel Sambuc __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a); 15704684ddb6SLionel Sambuc // __v.push_back(_VSTD::forward<_Up>(__x)); 15714684ddb6SLionel Sambuc __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(__v.__end_), _VSTD::forward<_Up>(__x)); 15724684ddb6SLionel Sambuc __v.__end_++; 15734684ddb6SLionel Sambuc __swap_out_circular_buffer(__v); 15744684ddb6SLionel Sambuc} 15754684ddb6SLionel Sambuc 15764684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 15774684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 15784684ddb6SLionel Sambucvoid 15794684ddb6SLionel Sambucvector<_Tp, _Allocator>::push_back(const_reference __x) 15804684ddb6SLionel Sambuc{ 15814684ddb6SLionel Sambuc if (this->__end_ != this->__end_cap()) 15824684ddb6SLionel Sambuc { 1583*0a6a1f1dSLionel Sambuc __RAII_IncreaseAnnotator __annotator(*this); 15844684ddb6SLionel Sambuc __alloc_traits::construct(this->__alloc(), 15854684ddb6SLionel Sambuc _VSTD::__to_raw_pointer(this->__end_), __x); 1586*0a6a1f1dSLionel Sambuc __annotator.__done(); 15874684ddb6SLionel Sambuc ++this->__end_; 15884684ddb6SLionel Sambuc } 15894684ddb6SLionel Sambuc else 15904684ddb6SLionel Sambuc __push_back_slow_path(__x); 15914684ddb6SLionel Sambuc} 15924684ddb6SLionel Sambuc 15934684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 15944684ddb6SLionel Sambuc 15954684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 15964684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 15974684ddb6SLionel Sambucvoid 15984684ddb6SLionel Sambucvector<_Tp, _Allocator>::push_back(value_type&& __x) 15994684ddb6SLionel Sambuc{ 16004684ddb6SLionel Sambuc if (this->__end_ < this->__end_cap()) 16014684ddb6SLionel Sambuc { 1602*0a6a1f1dSLionel Sambuc __RAII_IncreaseAnnotator __annotator(*this); 16034684ddb6SLionel Sambuc __alloc_traits::construct(this->__alloc(), 16044684ddb6SLionel Sambuc _VSTD::__to_raw_pointer(this->__end_), 16054684ddb6SLionel Sambuc _VSTD::move(__x)); 1606*0a6a1f1dSLionel Sambuc __annotator.__done(); 16074684ddb6SLionel Sambuc ++this->__end_; 16084684ddb6SLionel Sambuc } 16094684ddb6SLionel Sambuc else 16104684ddb6SLionel Sambuc __push_back_slow_path(_VSTD::move(__x)); 16114684ddb6SLionel Sambuc} 16124684ddb6SLionel Sambuc 16134684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_VARIADICS 16144684ddb6SLionel Sambuc 16154684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 16164684ddb6SLionel Sambuctemplate <class... _Args> 16174684ddb6SLionel Sambucvoid 16184684ddb6SLionel Sambucvector<_Tp, _Allocator>::__emplace_back_slow_path(_Args&&... __args) 16194684ddb6SLionel Sambuc{ 16204684ddb6SLionel Sambuc allocator_type& __a = this->__alloc(); 16214684ddb6SLionel Sambuc __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a); 16224684ddb6SLionel Sambuc// __v.emplace_back(_VSTD::forward<_Args>(__args)...); 16234684ddb6SLionel Sambuc __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(__v.__end_), _VSTD::forward<_Args>(__args)...); 16244684ddb6SLionel Sambuc __v.__end_++; 16254684ddb6SLionel Sambuc __swap_out_circular_buffer(__v); 16264684ddb6SLionel Sambuc} 16274684ddb6SLionel Sambuc 16284684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 16294684ddb6SLionel Sambuctemplate <class... _Args> 16304684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 16314684ddb6SLionel Sambucvoid 16324684ddb6SLionel Sambucvector<_Tp, _Allocator>::emplace_back(_Args&&... __args) 16334684ddb6SLionel Sambuc{ 16344684ddb6SLionel Sambuc if (this->__end_ < this->__end_cap()) 16354684ddb6SLionel Sambuc { 1636*0a6a1f1dSLionel Sambuc __RAII_IncreaseAnnotator __annotator(*this); 16374684ddb6SLionel Sambuc __alloc_traits::construct(this->__alloc(), 16384684ddb6SLionel Sambuc _VSTD::__to_raw_pointer(this->__end_), 16394684ddb6SLionel Sambuc _VSTD::forward<_Args>(__args)...); 1640*0a6a1f1dSLionel Sambuc __annotator.__done(); 16414684ddb6SLionel Sambuc ++this->__end_; 16424684ddb6SLionel Sambuc } 16434684ddb6SLionel Sambuc else 16444684ddb6SLionel Sambuc __emplace_back_slow_path(_VSTD::forward<_Args>(__args)...); 16454684ddb6SLionel Sambuc} 16464684ddb6SLionel Sambuc 16474684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_VARIADICS 16484684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 16494684ddb6SLionel Sambuc 16504684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 16514684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 16524684ddb6SLionel Sambucvoid 16534684ddb6SLionel Sambucvector<_Tp, _Allocator>::pop_back() 16544684ddb6SLionel Sambuc{ 16554684ddb6SLionel Sambuc _LIBCPP_ASSERT(!empty(), "vector::pop_back called for empty vector"); 16564684ddb6SLionel Sambuc this->__destruct_at_end(this->__end_ - 1); 16574684ddb6SLionel Sambuc} 16584684ddb6SLionel Sambuc 16594684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 16604684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 16614684ddb6SLionel Sambuctypename vector<_Tp, _Allocator>::iterator 16624684ddb6SLionel Sambucvector<_Tp, _Allocator>::erase(const_iterator __position) 16634684ddb6SLionel Sambuc{ 16644684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2 16654684ddb6SLionel Sambuc _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, 16664684ddb6SLionel Sambuc "vector::erase(iterator) called with an iterator not" 16674684ddb6SLionel Sambuc " referring to this vector"); 16684684ddb6SLionel Sambuc#endif 16694684ddb6SLionel Sambuc _LIBCPP_ASSERT(__position != end(), 16704684ddb6SLionel Sambuc "vector::erase(iterator) called with a non-dereferenceable iterator"); 16714684ddb6SLionel Sambuc difference_type __ps = __position - cbegin(); 16724684ddb6SLionel Sambuc pointer __p = this->__begin_ + __ps; 16734684ddb6SLionel Sambuc iterator __r = __make_iter(__p); 16744684ddb6SLionel Sambuc this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p)); 16754684ddb6SLionel Sambuc return __r; 16764684ddb6SLionel Sambuc} 16774684ddb6SLionel Sambuc 16784684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 16794684ddb6SLionel Sambuctypename vector<_Tp, _Allocator>::iterator 16804684ddb6SLionel Sambucvector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last) 16814684ddb6SLionel Sambuc{ 16824684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2 16834684ddb6SLionel Sambuc _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this, 16844684ddb6SLionel Sambuc "vector::erase(iterator, iterator) called with an iterator not" 16854684ddb6SLionel Sambuc " referring to this vector"); 16864684ddb6SLionel Sambuc#endif 16874684ddb6SLionel Sambuc _LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range"); 16884684ddb6SLionel Sambuc pointer __p = this->__begin_ + (__first - begin()); 16894684ddb6SLionel Sambuc iterator __r = __make_iter(__p); 16904684ddb6SLionel Sambuc if (__first != __last) 16914684ddb6SLionel Sambuc this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p)); 16924684ddb6SLionel Sambuc return __r; 16934684ddb6SLionel Sambuc} 16944684ddb6SLionel Sambuc 16954684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 16964684ddb6SLionel Sambucvoid 16974684ddb6SLionel Sambucvector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to) 16984684ddb6SLionel Sambuc{ 16994684ddb6SLionel Sambuc pointer __old_last = this->__end_; 17004684ddb6SLionel Sambuc difference_type __n = __old_last - __to; 17014684ddb6SLionel Sambuc for (pointer __i = __from_s + __n; __i < __from_e; ++__i, ++this->__end_) 17024684ddb6SLionel Sambuc __alloc_traits::construct(this->__alloc(), 17034684ddb6SLionel Sambuc _VSTD::__to_raw_pointer(this->__end_), 17044684ddb6SLionel Sambuc _VSTD::move(*__i)); 17054684ddb6SLionel Sambuc _VSTD::move_backward(__from_s, __from_s + __n, __old_last); 17064684ddb6SLionel Sambuc} 17074684ddb6SLionel Sambuc 17084684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 17094684ddb6SLionel Sambuctypename vector<_Tp, _Allocator>::iterator 17104684ddb6SLionel Sambucvector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x) 17114684ddb6SLionel Sambuc{ 17124684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2 17134684ddb6SLionel Sambuc _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, 17144684ddb6SLionel Sambuc "vector::insert(iterator, x) called with an iterator not" 17154684ddb6SLionel Sambuc " referring to this vector"); 17164684ddb6SLionel Sambuc#endif 17174684ddb6SLionel Sambuc pointer __p = this->__begin_ + (__position - begin()); 17184684ddb6SLionel Sambuc if (this->__end_ < this->__end_cap()) 17194684ddb6SLionel Sambuc { 1720*0a6a1f1dSLionel Sambuc __RAII_IncreaseAnnotator __annotator(*this); 17214684ddb6SLionel Sambuc if (__p == this->__end_) 17224684ddb6SLionel Sambuc { 17234684ddb6SLionel Sambuc __alloc_traits::construct(this->__alloc(), 17244684ddb6SLionel Sambuc _VSTD::__to_raw_pointer(this->__end_), __x); 17254684ddb6SLionel Sambuc ++this->__end_; 17264684ddb6SLionel Sambuc } 17274684ddb6SLionel Sambuc else 17284684ddb6SLionel Sambuc { 17294684ddb6SLionel Sambuc __move_range(__p, this->__end_, __p + 1); 17304684ddb6SLionel Sambuc const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x); 17314684ddb6SLionel Sambuc if (__p <= __xr && __xr < this->__end_) 17324684ddb6SLionel Sambuc ++__xr; 17334684ddb6SLionel Sambuc *__p = *__xr; 17344684ddb6SLionel Sambuc } 1735*0a6a1f1dSLionel Sambuc __annotator.__done(); 17364684ddb6SLionel Sambuc } 17374684ddb6SLionel Sambuc else 17384684ddb6SLionel Sambuc { 17394684ddb6SLionel Sambuc allocator_type& __a = this->__alloc(); 17404684ddb6SLionel Sambuc __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a); 17414684ddb6SLionel Sambuc __v.push_back(__x); 17424684ddb6SLionel Sambuc __p = __swap_out_circular_buffer(__v, __p); 17434684ddb6SLionel Sambuc } 17444684ddb6SLionel Sambuc return __make_iter(__p); 17454684ddb6SLionel Sambuc} 17464684ddb6SLionel Sambuc 17474684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 17484684ddb6SLionel Sambuc 17494684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 17504684ddb6SLionel Sambuctypename vector<_Tp, _Allocator>::iterator 17514684ddb6SLionel Sambucvector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x) 17524684ddb6SLionel Sambuc{ 17534684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2 17544684ddb6SLionel Sambuc _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, 17554684ddb6SLionel Sambuc "vector::insert(iterator, x) called with an iterator not" 17564684ddb6SLionel Sambuc " referring to this vector"); 17574684ddb6SLionel Sambuc#endif 17584684ddb6SLionel Sambuc pointer __p = this->__begin_ + (__position - begin()); 17594684ddb6SLionel Sambuc if (this->__end_ < this->__end_cap()) 17604684ddb6SLionel Sambuc { 1761*0a6a1f1dSLionel Sambuc __RAII_IncreaseAnnotator __annotator(*this); 17624684ddb6SLionel Sambuc if (__p == this->__end_) 17634684ddb6SLionel Sambuc { 17644684ddb6SLionel Sambuc __alloc_traits::construct(this->__alloc(), 17654684ddb6SLionel Sambuc _VSTD::__to_raw_pointer(this->__end_), 17664684ddb6SLionel Sambuc _VSTD::move(__x)); 17674684ddb6SLionel Sambuc ++this->__end_; 17684684ddb6SLionel Sambuc } 17694684ddb6SLionel Sambuc else 17704684ddb6SLionel Sambuc { 17714684ddb6SLionel Sambuc __move_range(__p, this->__end_, __p + 1); 17724684ddb6SLionel Sambuc *__p = _VSTD::move(__x); 17734684ddb6SLionel Sambuc } 1774*0a6a1f1dSLionel Sambuc __annotator.__done(); 17754684ddb6SLionel Sambuc } 17764684ddb6SLionel Sambuc else 17774684ddb6SLionel Sambuc { 17784684ddb6SLionel Sambuc allocator_type& __a = this->__alloc(); 17794684ddb6SLionel Sambuc __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a); 17804684ddb6SLionel Sambuc __v.push_back(_VSTD::move(__x)); 17814684ddb6SLionel Sambuc __p = __swap_out_circular_buffer(__v, __p); 17824684ddb6SLionel Sambuc } 17834684ddb6SLionel Sambuc return __make_iter(__p); 17844684ddb6SLionel Sambuc} 17854684ddb6SLionel Sambuc 17864684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_VARIADICS 17874684ddb6SLionel Sambuc 17884684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 17894684ddb6SLionel Sambuctemplate <class... _Args> 17904684ddb6SLionel Sambuctypename vector<_Tp, _Allocator>::iterator 17914684ddb6SLionel Sambucvector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args) 17924684ddb6SLionel Sambuc{ 17934684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2 17944684ddb6SLionel Sambuc _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, 17954684ddb6SLionel Sambuc "vector::emplace(iterator, x) called with an iterator not" 17964684ddb6SLionel Sambuc " referring to this vector"); 17974684ddb6SLionel Sambuc#endif 17984684ddb6SLionel Sambuc pointer __p = this->__begin_ + (__position - begin()); 17994684ddb6SLionel Sambuc if (this->__end_ < this->__end_cap()) 18004684ddb6SLionel Sambuc { 1801*0a6a1f1dSLionel Sambuc __RAII_IncreaseAnnotator __annotator(*this); 18024684ddb6SLionel Sambuc if (__p == this->__end_) 18034684ddb6SLionel Sambuc { 18044684ddb6SLionel Sambuc __alloc_traits::construct(this->__alloc(), 18054684ddb6SLionel Sambuc _VSTD::__to_raw_pointer(this->__end_), 18064684ddb6SLionel Sambuc _VSTD::forward<_Args>(__args)...); 18074684ddb6SLionel Sambuc ++this->__end_; 18084684ddb6SLionel Sambuc } 18094684ddb6SLionel Sambuc else 18104684ddb6SLionel Sambuc { 18114684ddb6SLionel Sambuc value_type __tmp(_VSTD::forward<_Args>(__args)...); 18124684ddb6SLionel Sambuc __move_range(__p, this->__end_, __p + 1); 18134684ddb6SLionel Sambuc *__p = _VSTD::move(__tmp); 18144684ddb6SLionel Sambuc } 1815*0a6a1f1dSLionel Sambuc __annotator.__done(); 18164684ddb6SLionel Sambuc } 18174684ddb6SLionel Sambuc else 18184684ddb6SLionel Sambuc { 18194684ddb6SLionel Sambuc allocator_type& __a = this->__alloc(); 18204684ddb6SLionel Sambuc __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a); 18214684ddb6SLionel Sambuc __v.emplace_back(_VSTD::forward<_Args>(__args)...); 18224684ddb6SLionel Sambuc __p = __swap_out_circular_buffer(__v, __p); 18234684ddb6SLionel Sambuc } 18244684ddb6SLionel Sambuc return __make_iter(__p); 18254684ddb6SLionel Sambuc} 18264684ddb6SLionel Sambuc 18274684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_VARIADICS 18284684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 18294684ddb6SLionel Sambuc 18304684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 18314684ddb6SLionel Sambuctypename vector<_Tp, _Allocator>::iterator 18324684ddb6SLionel Sambucvector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x) 18334684ddb6SLionel Sambuc{ 18344684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2 18354684ddb6SLionel Sambuc _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, 18364684ddb6SLionel Sambuc "vector::insert(iterator, n, x) called with an iterator not" 18374684ddb6SLionel Sambuc " referring to this vector"); 18384684ddb6SLionel Sambuc#endif 18394684ddb6SLionel Sambuc pointer __p = this->__begin_ + (__position - begin()); 18404684ddb6SLionel Sambuc if (__n > 0) 18414684ddb6SLionel Sambuc { 18424684ddb6SLionel Sambuc if (__n <= static_cast<size_type>(this->__end_cap() - this->__end_)) 18434684ddb6SLionel Sambuc { 18444684ddb6SLionel Sambuc size_type __old_n = __n; 18454684ddb6SLionel Sambuc pointer __old_last = this->__end_; 18464684ddb6SLionel Sambuc if (__n > static_cast<size_type>(this->__end_ - __p)) 18474684ddb6SLionel Sambuc { 18484684ddb6SLionel Sambuc size_type __cx = __n - (this->__end_ - __p); 18494684ddb6SLionel Sambuc __construct_at_end(__cx, __x); 18504684ddb6SLionel Sambuc __n -= __cx; 18514684ddb6SLionel Sambuc } 18524684ddb6SLionel Sambuc if (__n > 0) 18534684ddb6SLionel Sambuc { 1854*0a6a1f1dSLionel Sambuc __RAII_IncreaseAnnotator __annotator(*this, __n); 18554684ddb6SLionel Sambuc __move_range(__p, __old_last, __p + __old_n); 1856*0a6a1f1dSLionel Sambuc __annotator.__done(); 18574684ddb6SLionel Sambuc const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x); 18584684ddb6SLionel Sambuc if (__p <= __xr && __xr < this->__end_) 18594684ddb6SLionel Sambuc __xr += __old_n; 18604684ddb6SLionel Sambuc _VSTD::fill_n(__p, __n, *__xr); 18614684ddb6SLionel Sambuc } 18624684ddb6SLionel Sambuc } 18634684ddb6SLionel Sambuc else 18644684ddb6SLionel Sambuc { 18654684ddb6SLionel Sambuc allocator_type& __a = this->__alloc(); 18664684ddb6SLionel Sambuc __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a); 18674684ddb6SLionel Sambuc __v.__construct_at_end(__n, __x); 18684684ddb6SLionel Sambuc __p = __swap_out_circular_buffer(__v, __p); 18694684ddb6SLionel Sambuc } 18704684ddb6SLionel Sambuc } 18714684ddb6SLionel Sambuc return __make_iter(__p); 18724684ddb6SLionel Sambuc} 18734684ddb6SLionel Sambuc 18744684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 18754684ddb6SLionel Sambuctemplate <class _InputIterator> 18764684ddb6SLionel Sambuctypename enable_if 18774684ddb6SLionel Sambuc< 18784684ddb6SLionel Sambuc __is_input_iterator <_InputIterator>::value && 18794684ddb6SLionel Sambuc !__is_forward_iterator<_InputIterator>::value && 18804684ddb6SLionel Sambuc is_constructible< 18814684ddb6SLionel Sambuc _Tp, 18824684ddb6SLionel Sambuc typename iterator_traits<_InputIterator>::reference>::value, 18834684ddb6SLionel Sambuc typename vector<_Tp, _Allocator>::iterator 18844684ddb6SLionel Sambuc>::type 18854684ddb6SLionel Sambucvector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last) 18864684ddb6SLionel Sambuc{ 18874684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2 18884684ddb6SLionel Sambuc _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, 18894684ddb6SLionel Sambuc "vector::insert(iterator, range) called with an iterator not" 18904684ddb6SLionel Sambuc " referring to this vector"); 18914684ddb6SLionel Sambuc#endif 18924684ddb6SLionel Sambuc difference_type __off = __position - begin(); 18934684ddb6SLionel Sambuc pointer __p = this->__begin_ + __off; 18944684ddb6SLionel Sambuc allocator_type& __a = this->__alloc(); 18954684ddb6SLionel Sambuc pointer __old_last = this->__end_; 18964684ddb6SLionel Sambuc for (; this->__end_ != this->__end_cap() && __first != __last; ++__first) 18974684ddb6SLionel Sambuc { 1898*0a6a1f1dSLionel Sambuc __RAII_IncreaseAnnotator __annotator(*this); 18994684ddb6SLionel Sambuc __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), 19004684ddb6SLionel Sambuc *__first); 19014684ddb6SLionel Sambuc ++this->__end_; 1902*0a6a1f1dSLionel Sambuc __annotator.__done(); 19034684ddb6SLionel Sambuc } 19044684ddb6SLionel Sambuc __split_buffer<value_type, allocator_type&> __v(__a); 19054684ddb6SLionel Sambuc if (__first != __last) 19064684ddb6SLionel Sambuc { 19074684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 19084684ddb6SLionel Sambuc try 19094684ddb6SLionel Sambuc { 19104684ddb6SLionel Sambuc#endif // _LIBCPP_NO_EXCEPTIONS 19114684ddb6SLionel Sambuc __v.__construct_at_end(__first, __last); 19124684ddb6SLionel Sambuc difference_type __old_size = __old_last - this->__begin_; 19134684ddb6SLionel Sambuc difference_type __old_p = __p - this->__begin_; 19144684ddb6SLionel Sambuc reserve(__recommend(size() + __v.size())); 19154684ddb6SLionel Sambuc __p = this->__begin_ + __old_p; 19164684ddb6SLionel Sambuc __old_last = this->__begin_ + __old_size; 19174684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 19184684ddb6SLionel Sambuc } 19194684ddb6SLionel Sambuc catch (...) 19204684ddb6SLionel Sambuc { 19214684ddb6SLionel Sambuc erase(__make_iter(__old_last), end()); 19224684ddb6SLionel Sambuc throw; 19234684ddb6SLionel Sambuc } 19244684ddb6SLionel Sambuc#endif // _LIBCPP_NO_EXCEPTIONS 19254684ddb6SLionel Sambuc } 19264684ddb6SLionel Sambuc __p = _VSTD::rotate(__p, __old_last, this->__end_); 19274684ddb6SLionel Sambuc insert(__make_iter(__p), make_move_iterator(__v.begin()), 19284684ddb6SLionel Sambuc make_move_iterator(__v.end())); 19294684ddb6SLionel Sambuc return begin() + __off; 19304684ddb6SLionel Sambuc} 19314684ddb6SLionel Sambuc 19324684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 19334684ddb6SLionel Sambuctemplate <class _ForwardIterator> 19344684ddb6SLionel Sambuctypename enable_if 19354684ddb6SLionel Sambuc< 19364684ddb6SLionel Sambuc __is_forward_iterator<_ForwardIterator>::value && 19374684ddb6SLionel Sambuc is_constructible< 19384684ddb6SLionel Sambuc _Tp, 19394684ddb6SLionel Sambuc typename iterator_traits<_ForwardIterator>::reference>::value, 19404684ddb6SLionel Sambuc typename vector<_Tp, _Allocator>::iterator 19414684ddb6SLionel Sambuc>::type 19424684ddb6SLionel Sambucvector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last) 19434684ddb6SLionel Sambuc{ 19444684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2 19454684ddb6SLionel Sambuc _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, 19464684ddb6SLionel Sambuc "vector::insert(iterator, range) called with an iterator not" 19474684ddb6SLionel Sambuc " referring to this vector"); 19484684ddb6SLionel Sambuc#endif 19494684ddb6SLionel Sambuc pointer __p = this->__begin_ + (__position - begin()); 19504684ddb6SLionel Sambuc difference_type __n = _VSTD::distance(__first, __last); 19514684ddb6SLionel Sambuc if (__n > 0) 19524684ddb6SLionel Sambuc { 19534684ddb6SLionel Sambuc if (__n <= this->__end_cap() - this->__end_) 19544684ddb6SLionel Sambuc { 19554684ddb6SLionel Sambuc size_type __old_n = __n; 19564684ddb6SLionel Sambuc pointer __old_last = this->__end_; 19574684ddb6SLionel Sambuc _ForwardIterator __m = __last; 19584684ddb6SLionel Sambuc difference_type __dx = this->__end_ - __p; 19594684ddb6SLionel Sambuc if (__n > __dx) 19604684ddb6SLionel Sambuc { 19614684ddb6SLionel Sambuc __m = __first; 1962*0a6a1f1dSLionel Sambuc difference_type __diff = this->__end_ - __p; 1963*0a6a1f1dSLionel Sambuc _VSTD::advance(__m, __diff); 1964*0a6a1f1dSLionel Sambuc __construct_at_end(__m, __last, __n - __diff); 19654684ddb6SLionel Sambuc __n = __dx; 19664684ddb6SLionel Sambuc } 19674684ddb6SLionel Sambuc if (__n > 0) 19684684ddb6SLionel Sambuc { 1969*0a6a1f1dSLionel Sambuc __RAII_IncreaseAnnotator __annotator(*this, __n); 19704684ddb6SLionel Sambuc __move_range(__p, __old_last, __p + __old_n); 1971*0a6a1f1dSLionel Sambuc __annotator.__done(); 19724684ddb6SLionel Sambuc _VSTD::copy(__first, __m, __p); 19734684ddb6SLionel Sambuc } 19744684ddb6SLionel Sambuc } 19754684ddb6SLionel Sambuc else 19764684ddb6SLionel Sambuc { 19774684ddb6SLionel Sambuc allocator_type& __a = this->__alloc(); 19784684ddb6SLionel Sambuc __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a); 19794684ddb6SLionel Sambuc __v.__construct_at_end(__first, __last); 19804684ddb6SLionel Sambuc __p = __swap_out_circular_buffer(__v, __p); 19814684ddb6SLionel Sambuc } 19824684ddb6SLionel Sambuc } 19834684ddb6SLionel Sambuc return __make_iter(__p); 19844684ddb6SLionel Sambuc} 19854684ddb6SLionel Sambuc 19864684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 19874684ddb6SLionel Sambucvoid 19884684ddb6SLionel Sambucvector<_Tp, _Allocator>::resize(size_type __sz) 19894684ddb6SLionel Sambuc{ 19904684ddb6SLionel Sambuc size_type __cs = size(); 19914684ddb6SLionel Sambuc if (__cs < __sz) 19924684ddb6SLionel Sambuc this->__append(__sz - __cs); 19934684ddb6SLionel Sambuc else if (__cs > __sz) 19944684ddb6SLionel Sambuc this->__destruct_at_end(this->__begin_ + __sz); 19954684ddb6SLionel Sambuc} 19964684ddb6SLionel Sambuc 19974684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 19984684ddb6SLionel Sambucvoid 19994684ddb6SLionel Sambucvector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x) 20004684ddb6SLionel Sambuc{ 20014684ddb6SLionel Sambuc size_type __cs = size(); 20024684ddb6SLionel Sambuc if (__cs < __sz) 20034684ddb6SLionel Sambuc this->__append(__sz - __cs, __x); 20044684ddb6SLionel Sambuc else if (__cs > __sz) 20054684ddb6SLionel Sambuc this->__destruct_at_end(this->__begin_ + __sz); 20064684ddb6SLionel Sambuc} 20074684ddb6SLionel Sambuc 20084684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 20094684ddb6SLionel Sambucvoid 20104684ddb6SLionel Sambucvector<_Tp, _Allocator>::swap(vector& __x) 2011*0a6a1f1dSLionel Sambuc#if _LIBCPP_STD_VER >= 14 2012*0a6a1f1dSLionel Sambuc _NOEXCEPT 2013*0a6a1f1dSLionel Sambuc#else 20144684ddb6SLionel Sambuc _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || 20154684ddb6SLionel Sambuc __is_nothrow_swappable<allocator_type>::value) 2016*0a6a1f1dSLionel Sambuc#endif 20174684ddb6SLionel Sambuc{ 20184684ddb6SLionel Sambuc _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value || 20194684ddb6SLionel Sambuc this->__alloc() == __x.__alloc(), 20204684ddb6SLionel Sambuc "vector::swap: Either propagate_on_container_swap must be true" 20214684ddb6SLionel Sambuc " or the allocators must compare equal"); 20224684ddb6SLionel Sambuc _VSTD::swap(this->__begin_, __x.__begin_); 20234684ddb6SLionel Sambuc _VSTD::swap(this->__end_, __x.__end_); 20244684ddb6SLionel Sambuc _VSTD::swap(this->__end_cap(), __x.__end_cap()); 2025*0a6a1f1dSLionel Sambuc __swap_allocator(this->__alloc(), __x.__alloc(), 2026*0a6a1f1dSLionel Sambuc integral_constant<bool,__alloc_traits::propagate_on_container_swap::value>()); 20274684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2 20284684ddb6SLionel Sambuc __get_db()->swap(this, &__x); 20294684ddb6SLionel Sambuc#endif // _LIBCPP_DEBUG_LEVEL >= 2 20304684ddb6SLionel Sambuc} 20314684ddb6SLionel Sambuc 20324684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 20334684ddb6SLionel Sambucbool 20344684ddb6SLionel Sambucvector<_Tp, _Allocator>::__invariants() const 20354684ddb6SLionel Sambuc{ 20364684ddb6SLionel Sambuc if (this->__begin_ == nullptr) 20374684ddb6SLionel Sambuc { 20384684ddb6SLionel Sambuc if (this->__end_ != nullptr || this->__end_cap() != nullptr) 20394684ddb6SLionel Sambuc return false; 20404684ddb6SLionel Sambuc } 20414684ddb6SLionel Sambuc else 20424684ddb6SLionel Sambuc { 20434684ddb6SLionel Sambuc if (this->__begin_ > this->__end_) 20444684ddb6SLionel Sambuc return false; 20454684ddb6SLionel Sambuc if (this->__begin_ == this->__end_cap()) 20464684ddb6SLionel Sambuc return false; 20474684ddb6SLionel Sambuc if (this->__end_ > this->__end_cap()) 20484684ddb6SLionel Sambuc return false; 20494684ddb6SLionel Sambuc } 20504684ddb6SLionel Sambuc return true; 20514684ddb6SLionel Sambuc} 20524684ddb6SLionel Sambuc 20534684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2 20544684ddb6SLionel Sambuc 20554684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 20564684ddb6SLionel Sambucbool 20574684ddb6SLionel Sambucvector<_Tp, _Allocator>::__dereferenceable(const const_iterator* __i) const 20584684ddb6SLionel Sambuc{ 20594684ddb6SLionel Sambuc return this->__begin_ <= __i->base() && __i->base() < this->__end_; 20604684ddb6SLionel Sambuc} 20614684ddb6SLionel Sambuc 20624684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 20634684ddb6SLionel Sambucbool 20644684ddb6SLionel Sambucvector<_Tp, _Allocator>::__decrementable(const const_iterator* __i) const 20654684ddb6SLionel Sambuc{ 20664684ddb6SLionel Sambuc return this->__begin_ < __i->base() && __i->base() <= this->__end_; 20674684ddb6SLionel Sambuc} 20684684ddb6SLionel Sambuc 20694684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 20704684ddb6SLionel Sambucbool 20714684ddb6SLionel Sambucvector<_Tp, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const 20724684ddb6SLionel Sambuc{ 20734684ddb6SLionel Sambuc const_pointer __p = __i->base() + __n; 20744684ddb6SLionel Sambuc return this->__begin_ <= __p && __p <= this->__end_; 20754684ddb6SLionel Sambuc} 20764684ddb6SLionel Sambuc 20774684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 20784684ddb6SLionel Sambucbool 20794684ddb6SLionel Sambucvector<_Tp, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const 20804684ddb6SLionel Sambuc{ 20814684ddb6SLionel Sambuc const_pointer __p = __i->base() + __n; 20824684ddb6SLionel Sambuc return this->__begin_ <= __p && __p < this->__end_; 20834684ddb6SLionel Sambuc} 20844684ddb6SLionel Sambuc 20854684ddb6SLionel Sambuc#endif // _LIBCPP_DEBUG_LEVEL >= 2 20864684ddb6SLionel Sambuc 20874684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 20884684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 20894684ddb6SLionel Sambucvoid 20904684ddb6SLionel Sambucvector<_Tp, _Allocator>::__invalidate_all_iterators() 20914684ddb6SLionel Sambuc{ 20924684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2 20934684ddb6SLionel Sambuc __get_db()->__invalidate_all(this); 20944684ddb6SLionel Sambuc#endif // _LIBCPP_DEBUG_LEVEL >= 2 20954684ddb6SLionel Sambuc} 20964684ddb6SLionel Sambuc 20974684ddb6SLionel Sambuc// vector<bool> 20984684ddb6SLionel Sambuc 20994684ddb6SLionel Sambuctemplate <class _Allocator> class vector<bool, _Allocator>; 21004684ddb6SLionel Sambuc 21014684ddb6SLionel Sambuctemplate <class _Allocator> struct hash<vector<bool, _Allocator> >; 21024684ddb6SLionel Sambuc 21034684ddb6SLionel Sambuctemplate <class _Allocator> 21044684ddb6SLionel Sambucstruct __has_storage_type<vector<bool, _Allocator> > 21054684ddb6SLionel Sambuc{ 21064684ddb6SLionel Sambuc static const bool value = true; 21074684ddb6SLionel Sambuc}; 21084684ddb6SLionel Sambuc 21094684ddb6SLionel Sambuctemplate <class _Allocator> 21104684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY vector<bool, _Allocator> 21114684ddb6SLionel Sambuc : private __vector_base_common<true> 21124684ddb6SLionel Sambuc{ 21134684ddb6SLionel Sambucpublic: 21144684ddb6SLionel Sambuc typedef vector __self; 21154684ddb6SLionel Sambuc typedef bool value_type; 21164684ddb6SLionel Sambuc typedef _Allocator allocator_type; 21174684ddb6SLionel Sambuc typedef allocator_traits<allocator_type> __alloc_traits; 21184684ddb6SLionel Sambuc typedef typename __alloc_traits::size_type size_type; 21194684ddb6SLionel Sambuc typedef typename __alloc_traits::difference_type difference_type; 21204684ddb6SLionel Sambuc typedef size_type __storage_type; 21214684ddb6SLionel Sambuc typedef __bit_iterator<vector, false> pointer; 21224684ddb6SLionel Sambuc typedef __bit_iterator<vector, true> const_pointer; 21234684ddb6SLionel Sambuc typedef pointer iterator; 21244684ddb6SLionel Sambuc typedef const_pointer const_iterator; 21254684ddb6SLionel Sambuc typedef _VSTD::reverse_iterator<iterator> reverse_iterator; 21264684ddb6SLionel Sambuc typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; 21274684ddb6SLionel Sambuc 21284684ddb6SLionel Sambucprivate: 2129*0a6a1f1dSLionel Sambuc typedef typename __rebind_alloc_helper<__alloc_traits, __storage_type>::type __storage_allocator; 21304684ddb6SLionel Sambuc typedef allocator_traits<__storage_allocator> __storage_traits; 21314684ddb6SLionel Sambuc typedef typename __storage_traits::pointer __storage_pointer; 21324684ddb6SLionel Sambuc typedef typename __storage_traits::const_pointer __const_storage_pointer; 21334684ddb6SLionel Sambuc 21344684ddb6SLionel Sambuc __storage_pointer __begin_; 21354684ddb6SLionel Sambuc size_type __size_; 21364684ddb6SLionel Sambuc __compressed_pair<size_type, __storage_allocator> __cap_alloc_; 21374684ddb6SLionel Sambucpublic: 21384684ddb6SLionel Sambuc typedef __bit_reference<vector> reference; 21394684ddb6SLionel Sambuc typedef __bit_const_reference<vector> const_reference; 21404684ddb6SLionel Sambucprivate: 21414684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 21424684ddb6SLionel Sambuc size_type& __cap() _NOEXCEPT 21434684ddb6SLionel Sambuc {return __cap_alloc_.first();} 21444684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 21454684ddb6SLionel Sambuc const size_type& __cap() const _NOEXCEPT 21464684ddb6SLionel Sambuc {return __cap_alloc_.first();} 21474684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 21484684ddb6SLionel Sambuc __storage_allocator& __alloc() _NOEXCEPT 21494684ddb6SLionel Sambuc {return __cap_alloc_.second();} 21504684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 21514684ddb6SLionel Sambuc const __storage_allocator& __alloc() const _NOEXCEPT 21524684ddb6SLionel Sambuc {return __cap_alloc_.second();} 21534684ddb6SLionel Sambuc 21544684ddb6SLionel Sambuc static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); 21554684ddb6SLionel Sambuc 21564684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 21574684ddb6SLionel Sambuc static size_type __internal_cap_to_external(size_type __n) _NOEXCEPT 21584684ddb6SLionel Sambuc {return __n * __bits_per_word;} 21594684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 21604684ddb6SLionel Sambuc static size_type __external_cap_to_internal(size_type __n) _NOEXCEPT 21614684ddb6SLionel Sambuc {return (__n - 1) / __bits_per_word + 1;} 21624684ddb6SLionel Sambuc 21634684ddb6SLionel Sambucpublic: 21644684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 2165*0a6a1f1dSLionel Sambuc vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value); 2166*0a6a1f1dSLionel Sambuc 2167*0a6a1f1dSLionel Sambuc _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a) 2168*0a6a1f1dSLionel Sambuc#if _LIBCPP_STD_VER <= 14 2169*0a6a1f1dSLionel Sambuc _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value); 2170*0a6a1f1dSLionel Sambuc#else 2171*0a6a1f1dSLionel Sambuc _NOEXCEPT; 2172*0a6a1f1dSLionel Sambuc#endif 21734684ddb6SLionel Sambuc ~vector(); 21744684ddb6SLionel Sambuc explicit vector(size_type __n); 21754684ddb6SLionel Sambuc#if _LIBCPP_STD_VER > 11 21764684ddb6SLionel Sambuc explicit vector(size_type __n, const allocator_type& __a); 21774684ddb6SLionel Sambuc#endif 21784684ddb6SLionel Sambuc vector(size_type __n, const value_type& __v); 21794684ddb6SLionel Sambuc vector(size_type __n, const value_type& __v, const allocator_type& __a); 21804684ddb6SLionel Sambuc template <class _InputIterator> 21814684ddb6SLionel Sambuc vector(_InputIterator __first, _InputIterator __last, 21824684ddb6SLionel Sambuc typename enable_if<__is_input_iterator <_InputIterator>::value && 21834684ddb6SLionel Sambuc !__is_forward_iterator<_InputIterator>::value>::type* = 0); 21844684ddb6SLionel Sambuc template <class _InputIterator> 21854684ddb6SLionel Sambuc vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, 21864684ddb6SLionel Sambuc typename enable_if<__is_input_iterator <_InputIterator>::value && 21874684ddb6SLionel Sambuc !__is_forward_iterator<_InputIterator>::value>::type* = 0); 21884684ddb6SLionel Sambuc template <class _ForwardIterator> 21894684ddb6SLionel Sambuc vector(_ForwardIterator __first, _ForwardIterator __last, 21904684ddb6SLionel Sambuc typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0); 21914684ddb6SLionel Sambuc template <class _ForwardIterator> 21924684ddb6SLionel Sambuc vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, 21934684ddb6SLionel Sambuc typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0); 21944684ddb6SLionel Sambuc 21954684ddb6SLionel Sambuc vector(const vector& __v); 21964684ddb6SLionel Sambuc vector(const vector& __v, const allocator_type& __a); 21974684ddb6SLionel Sambuc vector& operator=(const vector& __v); 21984684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 21994684ddb6SLionel Sambuc vector(initializer_list<value_type> __il); 22004684ddb6SLionel Sambuc vector(initializer_list<value_type> __il, const allocator_type& __a); 22014684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 22024684ddb6SLionel Sambuc 22034684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 22044684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 22054684ddb6SLionel Sambuc vector(vector&& __v) 2206*0a6a1f1dSLionel Sambuc#if _LIBCPP_STD_VER > 14 2207*0a6a1f1dSLionel Sambuc _NOEXCEPT; 2208*0a6a1f1dSLionel Sambuc#else 22094684ddb6SLionel Sambuc _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); 2210*0a6a1f1dSLionel Sambuc#endif 22114684ddb6SLionel Sambuc vector(vector&& __v, const allocator_type& __a); 22124684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 22134684ddb6SLionel Sambuc vector& operator=(vector&& __v) 2214*0a6a1f1dSLionel Sambuc _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)); 22154684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 22164684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 22174684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 22184684ddb6SLionel Sambuc vector& operator=(initializer_list<value_type> __il) 22194684ddb6SLionel Sambuc {assign(__il.begin(), __il.end()); return *this;} 22204684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 22214684ddb6SLionel Sambuc 22224684ddb6SLionel Sambuc template <class _InputIterator> 22234684ddb6SLionel Sambuc typename enable_if 22244684ddb6SLionel Sambuc < 22254684ddb6SLionel Sambuc __is_input_iterator<_InputIterator>::value && 22264684ddb6SLionel Sambuc !__is_forward_iterator<_InputIterator>::value, 22274684ddb6SLionel Sambuc void 22284684ddb6SLionel Sambuc >::type 22294684ddb6SLionel Sambuc assign(_InputIterator __first, _InputIterator __last); 22304684ddb6SLionel Sambuc template <class _ForwardIterator> 22314684ddb6SLionel Sambuc typename enable_if 22324684ddb6SLionel Sambuc < 22334684ddb6SLionel Sambuc __is_forward_iterator<_ForwardIterator>::value, 22344684ddb6SLionel Sambuc void 22354684ddb6SLionel Sambuc >::type 22364684ddb6SLionel Sambuc assign(_ForwardIterator __first, _ForwardIterator __last); 22374684ddb6SLionel Sambuc 22384684ddb6SLionel Sambuc void assign(size_type __n, const value_type& __x); 22394684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 22404684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 22414684ddb6SLionel Sambuc void assign(initializer_list<value_type> __il) 22424684ddb6SLionel Sambuc {assign(__il.begin(), __il.end());} 22434684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 22444684ddb6SLionel Sambuc 22454684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT 22464684ddb6SLionel Sambuc {return allocator_type(this->__alloc());} 22474684ddb6SLionel Sambuc 22484684ddb6SLionel Sambuc size_type max_size() const _NOEXCEPT; 22494684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 22504684ddb6SLionel Sambuc size_type capacity() const _NOEXCEPT 22514684ddb6SLionel Sambuc {return __internal_cap_to_external(__cap());} 22524684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 22534684ddb6SLionel Sambuc size_type size() const _NOEXCEPT 22544684ddb6SLionel Sambuc {return __size_;} 22554684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 22564684ddb6SLionel Sambuc bool empty() const _NOEXCEPT 22574684ddb6SLionel Sambuc {return __size_ == 0;} 22584684ddb6SLionel Sambuc void reserve(size_type __n); 22594684ddb6SLionel Sambuc void shrink_to_fit() _NOEXCEPT; 22604684ddb6SLionel Sambuc 22614684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 22624684ddb6SLionel Sambuc iterator begin() _NOEXCEPT 22634684ddb6SLionel Sambuc {return __make_iter(0);} 22644684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 22654684ddb6SLionel Sambuc const_iterator begin() const _NOEXCEPT 22664684ddb6SLionel Sambuc {return __make_iter(0);} 22674684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 22684684ddb6SLionel Sambuc iterator end() _NOEXCEPT 22694684ddb6SLionel Sambuc {return __make_iter(__size_);} 22704684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 22714684ddb6SLionel Sambuc const_iterator end() const _NOEXCEPT 22724684ddb6SLionel Sambuc {return __make_iter(__size_);} 22734684ddb6SLionel Sambuc 22744684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 22754684ddb6SLionel Sambuc reverse_iterator rbegin() _NOEXCEPT 22764684ddb6SLionel Sambuc {return reverse_iterator(end());} 22774684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 22784684ddb6SLionel Sambuc const_reverse_iterator rbegin() const _NOEXCEPT 22794684ddb6SLionel Sambuc {return const_reverse_iterator(end());} 22804684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 22814684ddb6SLionel Sambuc reverse_iterator rend() _NOEXCEPT 22824684ddb6SLionel Sambuc {return reverse_iterator(begin());} 22834684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 22844684ddb6SLionel Sambuc const_reverse_iterator rend() const _NOEXCEPT 22854684ddb6SLionel Sambuc {return const_reverse_iterator(begin());} 22864684ddb6SLionel Sambuc 22874684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 22884684ddb6SLionel Sambuc const_iterator cbegin() const _NOEXCEPT 22894684ddb6SLionel Sambuc {return __make_iter(0);} 22904684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 22914684ddb6SLionel Sambuc const_iterator cend() const _NOEXCEPT 22924684ddb6SLionel Sambuc {return __make_iter(__size_);} 22934684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 22944684ddb6SLionel Sambuc const_reverse_iterator crbegin() const _NOEXCEPT 22954684ddb6SLionel Sambuc {return rbegin();} 22964684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 22974684ddb6SLionel Sambuc const_reverse_iterator crend() const _NOEXCEPT 22984684ddb6SLionel Sambuc {return rend();} 22994684ddb6SLionel Sambuc 23004684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) {return __make_ref(__n);} 23014684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const {return __make_ref(__n);} 23024684ddb6SLionel Sambuc reference at(size_type __n); 23034684ddb6SLionel Sambuc const_reference at(size_type __n) const; 23044684ddb6SLionel Sambuc 23054684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY reference front() {return __make_ref(0);} 23064684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY const_reference front() const {return __make_ref(0);} 23074684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY reference back() {return __make_ref(__size_ - 1);} 23084684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY const_reference back() const {return __make_ref(__size_ - 1);} 23094684ddb6SLionel Sambuc 23104684ddb6SLionel Sambuc void push_back(const value_type& __x); 23114684ddb6SLionel Sambuc#if _LIBCPP_STD_VER > 11 23124684ddb6SLionel Sambuc template <class... _Args> 23134684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY void emplace_back(_Args&&... __args) 23144684ddb6SLionel Sambuc { push_back ( value_type ( _VSTD::forward<_Args>(__args)... )); } 23154684ddb6SLionel Sambuc#endif 23164684ddb6SLionel Sambuc 23174684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY void pop_back() {--__size_;} 23184684ddb6SLionel Sambuc 23194684ddb6SLionel Sambuc#if _LIBCPP_STD_VER > 11 23204684ddb6SLionel Sambuc template <class... _Args> 23214684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY iterator emplace(const_iterator position, _Args&&... __args) 23224684ddb6SLionel Sambuc { return insert ( position, value_type ( _VSTD::forward<_Args>(__args)... )); } 23234684ddb6SLionel Sambuc#endif 23244684ddb6SLionel Sambuc 23254684ddb6SLionel Sambuc iterator insert(const_iterator __position, const value_type& __x); 23264684ddb6SLionel Sambuc iterator insert(const_iterator __position, size_type __n, const value_type& __x); 23274684ddb6SLionel Sambuc iterator insert(const_iterator __position, size_type __n, const_reference __x); 23284684ddb6SLionel Sambuc template <class _InputIterator> 23294684ddb6SLionel Sambuc typename enable_if 23304684ddb6SLionel Sambuc < 23314684ddb6SLionel Sambuc __is_input_iterator <_InputIterator>::value && 23324684ddb6SLionel Sambuc !__is_forward_iterator<_InputIterator>::value, 23334684ddb6SLionel Sambuc iterator 23344684ddb6SLionel Sambuc >::type 23354684ddb6SLionel Sambuc insert(const_iterator __position, _InputIterator __first, _InputIterator __last); 23364684ddb6SLionel Sambuc template <class _ForwardIterator> 23374684ddb6SLionel Sambuc typename enable_if 23384684ddb6SLionel Sambuc < 23394684ddb6SLionel Sambuc __is_forward_iterator<_ForwardIterator>::value, 23404684ddb6SLionel Sambuc iterator 23414684ddb6SLionel Sambuc >::type 23424684ddb6SLionel Sambuc insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last); 23434684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 23444684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 23454684ddb6SLionel Sambuc iterator insert(const_iterator __position, initializer_list<value_type> __il) 23464684ddb6SLionel Sambuc {return insert(__position, __il.begin(), __il.end());} 23474684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 23484684ddb6SLionel Sambuc 23494684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position); 23504684ddb6SLionel Sambuc iterator erase(const_iterator __first, const_iterator __last); 23514684ddb6SLionel Sambuc 23524684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 23534684ddb6SLionel Sambuc void clear() _NOEXCEPT {__size_ = 0;} 23544684ddb6SLionel Sambuc 23554684ddb6SLionel Sambuc void swap(vector&) 2356*0a6a1f1dSLionel Sambuc#if _LIBCPP_STD_VER >= 14 2357*0a6a1f1dSLionel Sambuc _NOEXCEPT; 2358*0a6a1f1dSLionel Sambuc#else 23594684ddb6SLionel Sambuc _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || 23604684ddb6SLionel Sambuc __is_nothrow_swappable<allocator_type>::value); 2361*0a6a1f1dSLionel Sambuc#endif 23624684ddb6SLionel Sambuc 23634684ddb6SLionel Sambuc void resize(size_type __sz, value_type __x = false); 23644684ddb6SLionel Sambuc void flip() _NOEXCEPT; 23654684ddb6SLionel Sambuc 23664684ddb6SLionel Sambuc bool __invariants() const; 23674684ddb6SLionel Sambuc 23684684ddb6SLionel Sambucprivate: 23694684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators(); 23704684ddb6SLionel Sambuc void allocate(size_type __n); 23714684ddb6SLionel Sambuc void deallocate() _NOEXCEPT; 23724684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 23734684ddb6SLionel Sambuc static size_type __align_it(size_type __new_size) _NOEXCEPT 2374*0a6a1f1dSLionel Sambuc {return __new_size + (__bits_per_word-1) & ~((size_type)__bits_per_word-1);}; 23754684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const; 23764684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY void __construct_at_end(size_type __n, bool __x); 23774684ddb6SLionel Sambuc template <class _ForwardIterator> 23784684ddb6SLionel Sambuc typename enable_if 23794684ddb6SLionel Sambuc < 23804684ddb6SLionel Sambuc __is_forward_iterator<_ForwardIterator>::value, 23814684ddb6SLionel Sambuc void 23824684ddb6SLionel Sambuc >::type 23834684ddb6SLionel Sambuc __construct_at_end(_ForwardIterator __first, _ForwardIterator __last); 23844684ddb6SLionel Sambuc void __append(size_type __n, const_reference __x); 23854684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 23864684ddb6SLionel Sambuc reference __make_ref(size_type __pos) _NOEXCEPT 23874684ddb6SLionel Sambuc {return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);} 23884684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 23894684ddb6SLionel Sambuc const_reference __make_ref(size_type __pos) const _NOEXCEPT 23904684ddb6SLionel Sambuc {return const_reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);} 23914684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 23924684ddb6SLionel Sambuc iterator __make_iter(size_type __pos) _NOEXCEPT 23934684ddb6SLionel Sambuc {return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));} 23944684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 23954684ddb6SLionel Sambuc const_iterator __make_iter(size_type __pos) const _NOEXCEPT 23964684ddb6SLionel Sambuc {return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));} 23974684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 23984684ddb6SLionel Sambuc iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT 23994684ddb6SLionel Sambuc {return begin() + (__p - cbegin());} 24004684ddb6SLionel Sambuc 24014684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 24024684ddb6SLionel Sambuc void __copy_assign_alloc(const vector& __v) 24034684ddb6SLionel Sambuc {__copy_assign_alloc(__v, integral_constant<bool, 24044684ddb6SLionel Sambuc __storage_traits::propagate_on_container_copy_assignment::value>());} 24054684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 24064684ddb6SLionel Sambuc void __copy_assign_alloc(const vector& __c, true_type) 24074684ddb6SLionel Sambuc { 24084684ddb6SLionel Sambuc if (__alloc() != __c.__alloc()) 24094684ddb6SLionel Sambuc deallocate(); 24104684ddb6SLionel Sambuc __alloc() = __c.__alloc(); 24114684ddb6SLionel Sambuc } 24124684ddb6SLionel Sambuc 24134684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 24144684ddb6SLionel Sambuc void __copy_assign_alloc(const vector&, false_type) 24154684ddb6SLionel Sambuc {} 24164684ddb6SLionel Sambuc 24174684ddb6SLionel Sambuc void __move_assign(vector& __c, false_type); 24184684ddb6SLionel Sambuc void __move_assign(vector& __c, true_type) 24194684ddb6SLionel Sambuc _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); 24204684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 24214684ddb6SLionel Sambuc void __move_assign_alloc(vector& __c) 24224684ddb6SLionel Sambuc _NOEXCEPT_( 24234684ddb6SLionel Sambuc !__storage_traits::propagate_on_container_move_assignment::value || 24244684ddb6SLionel Sambuc is_nothrow_move_assignable<allocator_type>::value) 24254684ddb6SLionel Sambuc {__move_assign_alloc(__c, integral_constant<bool, 24264684ddb6SLionel Sambuc __storage_traits::propagate_on_container_move_assignment::value>());} 24274684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 24284684ddb6SLionel Sambuc void __move_assign_alloc(vector& __c, true_type) 24294684ddb6SLionel Sambuc _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) 24304684ddb6SLionel Sambuc { 24314684ddb6SLionel Sambuc __alloc() = _VSTD::move(__c.__alloc()); 24324684ddb6SLionel Sambuc } 24334684ddb6SLionel Sambuc 24344684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 24354684ddb6SLionel Sambuc void __move_assign_alloc(vector&, false_type) 24364684ddb6SLionel Sambuc _NOEXCEPT 24374684ddb6SLionel Sambuc {} 24384684ddb6SLionel Sambuc 24394684ddb6SLionel Sambuc size_t __hash_code() const _NOEXCEPT; 24404684ddb6SLionel Sambuc 24414684ddb6SLionel Sambuc friend class __bit_reference<vector>; 24424684ddb6SLionel Sambuc friend class __bit_const_reference<vector>; 24434684ddb6SLionel Sambuc friend class __bit_iterator<vector, false>; 24444684ddb6SLionel Sambuc friend class __bit_iterator<vector, true>; 24454684ddb6SLionel Sambuc friend struct __bit_array<vector>; 24464684ddb6SLionel Sambuc friend struct _LIBCPP_TYPE_VIS_ONLY hash<vector>; 24474684ddb6SLionel Sambuc}; 24484684ddb6SLionel Sambuc 24494684ddb6SLionel Sambuctemplate <class _Allocator> 24504684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 24514684ddb6SLionel Sambucvoid 24524684ddb6SLionel Sambucvector<bool, _Allocator>::__invalidate_all_iterators() 24534684ddb6SLionel Sambuc{ 24544684ddb6SLionel Sambuc} 24554684ddb6SLionel Sambuc 24564684ddb6SLionel Sambuc// Allocate space for __n objects 24574684ddb6SLionel Sambuc// throws length_error if __n > max_size() 24584684ddb6SLionel Sambuc// throws (probably bad_alloc) if memory run out 24594684ddb6SLionel Sambuc// Precondition: __begin_ == __end_ == __cap() == 0 24604684ddb6SLionel Sambuc// Precondition: __n > 0 24614684ddb6SLionel Sambuc// Postcondition: capacity() == __n 24624684ddb6SLionel Sambuc// Postcondition: size() == 0 24634684ddb6SLionel Sambuctemplate <class _Allocator> 24644684ddb6SLionel Sambucvoid 24654684ddb6SLionel Sambucvector<bool, _Allocator>::allocate(size_type __n) 24664684ddb6SLionel Sambuc{ 24674684ddb6SLionel Sambuc if (__n > max_size()) 24684684ddb6SLionel Sambuc this->__throw_length_error(); 24694684ddb6SLionel Sambuc __n = __external_cap_to_internal(__n); 24704684ddb6SLionel Sambuc this->__begin_ = __storage_traits::allocate(this->__alloc(), __n); 24714684ddb6SLionel Sambuc this->__size_ = 0; 24724684ddb6SLionel Sambuc this->__cap() = __n; 24734684ddb6SLionel Sambuc} 24744684ddb6SLionel Sambuc 24754684ddb6SLionel Sambuctemplate <class _Allocator> 24764684ddb6SLionel Sambucvoid 24774684ddb6SLionel Sambucvector<bool, _Allocator>::deallocate() _NOEXCEPT 24784684ddb6SLionel Sambuc{ 24794684ddb6SLionel Sambuc if (this->__begin_ != nullptr) 24804684ddb6SLionel Sambuc { 24814684ddb6SLionel Sambuc __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap()); 24824684ddb6SLionel Sambuc __invalidate_all_iterators(); 24834684ddb6SLionel Sambuc this->__begin_ = nullptr; 24844684ddb6SLionel Sambuc this->__size_ = this->__cap() = 0; 24854684ddb6SLionel Sambuc } 24864684ddb6SLionel Sambuc} 24874684ddb6SLionel Sambuc 24884684ddb6SLionel Sambuctemplate <class _Allocator> 24894684ddb6SLionel Sambuctypename vector<bool, _Allocator>::size_type 24904684ddb6SLionel Sambucvector<bool, _Allocator>::max_size() const _NOEXCEPT 24914684ddb6SLionel Sambuc{ 24924684ddb6SLionel Sambuc size_type __amax = __storage_traits::max_size(__alloc()); 24934684ddb6SLionel Sambuc size_type __nmax = numeric_limits<size_type>::max() / 2; // end() >= begin(), always 24944684ddb6SLionel Sambuc if (__nmax / __bits_per_word <= __amax) 24954684ddb6SLionel Sambuc return __nmax; 24964684ddb6SLionel Sambuc return __internal_cap_to_external(__amax); 24974684ddb6SLionel Sambuc} 24984684ddb6SLionel Sambuc 24994684ddb6SLionel Sambuc// Precondition: __new_size > capacity() 25004684ddb6SLionel Sambuctemplate <class _Allocator> 25014684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 25024684ddb6SLionel Sambuctypename vector<bool, _Allocator>::size_type 25034684ddb6SLionel Sambucvector<bool, _Allocator>::__recommend(size_type __new_size) const 25044684ddb6SLionel Sambuc{ 25054684ddb6SLionel Sambuc const size_type __ms = max_size(); 25064684ddb6SLionel Sambuc if (__new_size > __ms) 25074684ddb6SLionel Sambuc this->__throw_length_error(); 25084684ddb6SLionel Sambuc const size_type __cap = capacity(); 25094684ddb6SLionel Sambuc if (__cap >= __ms / 2) 25104684ddb6SLionel Sambuc return __ms; 25114684ddb6SLionel Sambuc return _VSTD::max(2*__cap, __align_it(__new_size)); 25124684ddb6SLionel Sambuc} 25134684ddb6SLionel Sambuc 25144684ddb6SLionel Sambuc// Default constructs __n objects starting at __end_ 25154684ddb6SLionel Sambuc// Precondition: __n > 0 25164684ddb6SLionel Sambuc// Precondition: size() + __n <= capacity() 25174684ddb6SLionel Sambuc// Postcondition: size() == size() + __n 25184684ddb6SLionel Sambuctemplate <class _Allocator> 25194684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 25204684ddb6SLionel Sambucvoid 25214684ddb6SLionel Sambucvector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x) 25224684ddb6SLionel Sambuc{ 25234684ddb6SLionel Sambuc size_type __old_size = this->__size_; 25244684ddb6SLionel Sambuc this->__size_ += __n; 25254684ddb6SLionel Sambuc _VSTD::fill_n(__make_iter(__old_size), __n, __x); 25264684ddb6SLionel Sambuc} 25274684ddb6SLionel Sambuc 25284684ddb6SLionel Sambuctemplate <class _Allocator> 25294684ddb6SLionel Sambuctemplate <class _ForwardIterator> 25304684ddb6SLionel Sambuctypename enable_if 25314684ddb6SLionel Sambuc< 25324684ddb6SLionel Sambuc __is_forward_iterator<_ForwardIterator>::value, 25334684ddb6SLionel Sambuc void 25344684ddb6SLionel Sambuc>::type 25354684ddb6SLionel Sambucvector<bool, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last) 25364684ddb6SLionel Sambuc{ 25374684ddb6SLionel Sambuc size_type __old_size = this->__size_; 25384684ddb6SLionel Sambuc this->__size_ += _VSTD::distance(__first, __last); 25394684ddb6SLionel Sambuc _VSTD::copy(__first, __last, __make_iter(__old_size)); 25404684ddb6SLionel Sambuc} 25414684ddb6SLionel Sambuc 25424684ddb6SLionel Sambuctemplate <class _Allocator> 25434684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 25444684ddb6SLionel Sambucvector<bool, _Allocator>::vector() 25454684ddb6SLionel Sambuc _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) 25464684ddb6SLionel Sambuc : __begin_(nullptr), 25474684ddb6SLionel Sambuc __size_(0), 25484684ddb6SLionel Sambuc __cap_alloc_(0) 25494684ddb6SLionel Sambuc{ 25504684ddb6SLionel Sambuc} 25514684ddb6SLionel Sambuc 25524684ddb6SLionel Sambuctemplate <class _Allocator> 25534684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 25544684ddb6SLionel Sambucvector<bool, _Allocator>::vector(const allocator_type& __a) 2555*0a6a1f1dSLionel Sambuc#if _LIBCPP_STD_VER <= 14 2556*0a6a1f1dSLionel Sambuc _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value) 2557*0a6a1f1dSLionel Sambuc#else 2558*0a6a1f1dSLionel Sambuc _NOEXCEPT 2559*0a6a1f1dSLionel Sambuc#endif 25604684ddb6SLionel Sambuc : __begin_(nullptr), 25614684ddb6SLionel Sambuc __size_(0), 25624684ddb6SLionel Sambuc __cap_alloc_(0, static_cast<__storage_allocator>(__a)) 25634684ddb6SLionel Sambuc{ 25644684ddb6SLionel Sambuc} 25654684ddb6SLionel Sambuc 25664684ddb6SLionel Sambuctemplate <class _Allocator> 25674684ddb6SLionel Sambucvector<bool, _Allocator>::vector(size_type __n) 25684684ddb6SLionel Sambuc : __begin_(nullptr), 25694684ddb6SLionel Sambuc __size_(0), 25704684ddb6SLionel Sambuc __cap_alloc_(0) 25714684ddb6SLionel Sambuc{ 25724684ddb6SLionel Sambuc if (__n > 0) 25734684ddb6SLionel Sambuc { 25744684ddb6SLionel Sambuc allocate(__n); 25754684ddb6SLionel Sambuc __construct_at_end(__n, false); 25764684ddb6SLionel Sambuc } 25774684ddb6SLionel Sambuc} 25784684ddb6SLionel Sambuc 25794684ddb6SLionel Sambuc#if _LIBCPP_STD_VER > 11 25804684ddb6SLionel Sambuctemplate <class _Allocator> 25814684ddb6SLionel Sambucvector<bool, _Allocator>::vector(size_type __n, const allocator_type& __a) 25824684ddb6SLionel Sambuc : __begin_(nullptr), 25834684ddb6SLionel Sambuc __size_(0), 25844684ddb6SLionel Sambuc __cap_alloc_(0, static_cast<__storage_allocator>(__a)) 25854684ddb6SLionel Sambuc{ 25864684ddb6SLionel Sambuc if (__n > 0) 25874684ddb6SLionel Sambuc { 25884684ddb6SLionel Sambuc allocate(__n); 25894684ddb6SLionel Sambuc __construct_at_end(__n, false); 25904684ddb6SLionel Sambuc } 25914684ddb6SLionel Sambuc} 25924684ddb6SLionel Sambuc#endif 25934684ddb6SLionel Sambuc 25944684ddb6SLionel Sambuctemplate <class _Allocator> 25954684ddb6SLionel Sambucvector<bool, _Allocator>::vector(size_type __n, const value_type& __x) 25964684ddb6SLionel Sambuc : __begin_(nullptr), 25974684ddb6SLionel Sambuc __size_(0), 25984684ddb6SLionel Sambuc __cap_alloc_(0) 25994684ddb6SLionel Sambuc{ 26004684ddb6SLionel Sambuc if (__n > 0) 26014684ddb6SLionel Sambuc { 26024684ddb6SLionel Sambuc allocate(__n); 26034684ddb6SLionel Sambuc __construct_at_end(__n, __x); 26044684ddb6SLionel Sambuc } 26054684ddb6SLionel Sambuc} 26064684ddb6SLionel Sambuc 26074684ddb6SLionel Sambuctemplate <class _Allocator> 26084684ddb6SLionel Sambucvector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a) 26094684ddb6SLionel Sambuc : __begin_(nullptr), 26104684ddb6SLionel Sambuc __size_(0), 26114684ddb6SLionel Sambuc __cap_alloc_(0, static_cast<__storage_allocator>(__a)) 26124684ddb6SLionel Sambuc{ 26134684ddb6SLionel Sambuc if (__n > 0) 26144684ddb6SLionel Sambuc { 26154684ddb6SLionel Sambuc allocate(__n); 26164684ddb6SLionel Sambuc __construct_at_end(__n, __x); 26174684ddb6SLionel Sambuc } 26184684ddb6SLionel Sambuc} 26194684ddb6SLionel Sambuc 26204684ddb6SLionel Sambuctemplate <class _Allocator> 26214684ddb6SLionel Sambuctemplate <class _InputIterator> 26224684ddb6SLionel Sambucvector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, 26234684ddb6SLionel Sambuc typename enable_if<__is_input_iterator <_InputIterator>::value && 26244684ddb6SLionel Sambuc !__is_forward_iterator<_InputIterator>::value>::type*) 26254684ddb6SLionel Sambuc : __begin_(nullptr), 26264684ddb6SLionel Sambuc __size_(0), 26274684ddb6SLionel Sambuc __cap_alloc_(0) 26284684ddb6SLionel Sambuc{ 26294684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 26304684ddb6SLionel Sambuc try 26314684ddb6SLionel Sambuc { 26324684ddb6SLionel Sambuc#endif // _LIBCPP_NO_EXCEPTIONS 26334684ddb6SLionel Sambuc for (; __first != __last; ++__first) 26344684ddb6SLionel Sambuc push_back(*__first); 26354684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 26364684ddb6SLionel Sambuc } 26374684ddb6SLionel Sambuc catch (...) 26384684ddb6SLionel Sambuc { 26394684ddb6SLionel Sambuc if (__begin_ != nullptr) 26404684ddb6SLionel Sambuc __storage_traits::deallocate(__alloc(), __begin_, __cap()); 26414684ddb6SLionel Sambuc __invalidate_all_iterators(); 26424684ddb6SLionel Sambuc throw; 26434684ddb6SLionel Sambuc } 26444684ddb6SLionel Sambuc#endif // _LIBCPP_NO_EXCEPTIONS 26454684ddb6SLionel Sambuc} 26464684ddb6SLionel Sambuc 26474684ddb6SLionel Sambuctemplate <class _Allocator> 26484684ddb6SLionel Sambuctemplate <class _InputIterator> 26494684ddb6SLionel Sambucvector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, 26504684ddb6SLionel Sambuc typename enable_if<__is_input_iterator <_InputIterator>::value && 26514684ddb6SLionel Sambuc !__is_forward_iterator<_InputIterator>::value>::type*) 26524684ddb6SLionel Sambuc : __begin_(nullptr), 26534684ddb6SLionel Sambuc __size_(0), 26544684ddb6SLionel Sambuc __cap_alloc_(0, static_cast<__storage_allocator>(__a)) 26554684ddb6SLionel Sambuc{ 26564684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 26574684ddb6SLionel Sambuc try 26584684ddb6SLionel Sambuc { 26594684ddb6SLionel Sambuc#endif // _LIBCPP_NO_EXCEPTIONS 26604684ddb6SLionel Sambuc for (; __first != __last; ++__first) 26614684ddb6SLionel Sambuc push_back(*__first); 26624684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 26634684ddb6SLionel Sambuc } 26644684ddb6SLionel Sambuc catch (...) 26654684ddb6SLionel Sambuc { 26664684ddb6SLionel Sambuc if (__begin_ != nullptr) 26674684ddb6SLionel Sambuc __storage_traits::deallocate(__alloc(), __begin_, __cap()); 26684684ddb6SLionel Sambuc __invalidate_all_iterators(); 26694684ddb6SLionel Sambuc throw; 26704684ddb6SLionel Sambuc } 26714684ddb6SLionel Sambuc#endif // _LIBCPP_NO_EXCEPTIONS 26724684ddb6SLionel Sambuc} 26734684ddb6SLionel Sambuc 26744684ddb6SLionel Sambuctemplate <class _Allocator> 26754684ddb6SLionel Sambuctemplate <class _ForwardIterator> 26764684ddb6SLionel Sambucvector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, 26774684ddb6SLionel Sambuc typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*) 26784684ddb6SLionel Sambuc : __begin_(nullptr), 26794684ddb6SLionel Sambuc __size_(0), 26804684ddb6SLionel Sambuc __cap_alloc_(0) 26814684ddb6SLionel Sambuc{ 26824684ddb6SLionel Sambuc size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); 26834684ddb6SLionel Sambuc if (__n > 0) 26844684ddb6SLionel Sambuc { 26854684ddb6SLionel Sambuc allocate(__n); 26864684ddb6SLionel Sambuc __construct_at_end(__first, __last); 26874684ddb6SLionel Sambuc } 26884684ddb6SLionel Sambuc} 26894684ddb6SLionel Sambuc 26904684ddb6SLionel Sambuctemplate <class _Allocator> 26914684ddb6SLionel Sambuctemplate <class _ForwardIterator> 26924684ddb6SLionel Sambucvector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, 26934684ddb6SLionel Sambuc typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*) 26944684ddb6SLionel Sambuc : __begin_(nullptr), 26954684ddb6SLionel Sambuc __size_(0), 26964684ddb6SLionel Sambuc __cap_alloc_(0, static_cast<__storage_allocator>(__a)) 26974684ddb6SLionel Sambuc{ 26984684ddb6SLionel Sambuc size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); 26994684ddb6SLionel Sambuc if (__n > 0) 27004684ddb6SLionel Sambuc { 27014684ddb6SLionel Sambuc allocate(__n); 27024684ddb6SLionel Sambuc __construct_at_end(__first, __last); 27034684ddb6SLionel Sambuc } 27044684ddb6SLionel Sambuc} 27054684ddb6SLionel Sambuc 27064684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 27074684ddb6SLionel Sambuc 27084684ddb6SLionel Sambuctemplate <class _Allocator> 27094684ddb6SLionel Sambucvector<bool, _Allocator>::vector(initializer_list<value_type> __il) 27104684ddb6SLionel Sambuc : __begin_(nullptr), 27114684ddb6SLionel Sambuc __size_(0), 27124684ddb6SLionel Sambuc __cap_alloc_(0) 27134684ddb6SLionel Sambuc{ 27144684ddb6SLionel Sambuc size_type __n = static_cast<size_type>(__il.size()); 27154684ddb6SLionel Sambuc if (__n > 0) 27164684ddb6SLionel Sambuc { 27174684ddb6SLionel Sambuc allocate(__n); 27184684ddb6SLionel Sambuc __construct_at_end(__il.begin(), __il.end()); 27194684ddb6SLionel Sambuc } 27204684ddb6SLionel Sambuc} 27214684ddb6SLionel Sambuc 27224684ddb6SLionel Sambuctemplate <class _Allocator> 27234684ddb6SLionel Sambucvector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a) 27244684ddb6SLionel Sambuc : __begin_(nullptr), 27254684ddb6SLionel Sambuc __size_(0), 27264684ddb6SLionel Sambuc __cap_alloc_(0, static_cast<__storage_allocator>(__a)) 27274684ddb6SLionel Sambuc{ 27284684ddb6SLionel Sambuc size_type __n = static_cast<size_type>(__il.size()); 27294684ddb6SLionel Sambuc if (__n > 0) 27304684ddb6SLionel Sambuc { 27314684ddb6SLionel Sambuc allocate(__n); 27324684ddb6SLionel Sambuc __construct_at_end(__il.begin(), __il.end()); 27334684ddb6SLionel Sambuc } 27344684ddb6SLionel Sambuc} 27354684ddb6SLionel Sambuc 27364684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 27374684ddb6SLionel Sambuc 27384684ddb6SLionel Sambuctemplate <class _Allocator> 27394684ddb6SLionel Sambucvector<bool, _Allocator>::~vector() 27404684ddb6SLionel Sambuc{ 27414684ddb6SLionel Sambuc if (__begin_ != nullptr) 27424684ddb6SLionel Sambuc __storage_traits::deallocate(__alloc(), __begin_, __cap()); 27434684ddb6SLionel Sambuc __invalidate_all_iterators(); 27444684ddb6SLionel Sambuc} 27454684ddb6SLionel Sambuc 27464684ddb6SLionel Sambuctemplate <class _Allocator> 27474684ddb6SLionel Sambucvector<bool, _Allocator>::vector(const vector& __v) 27484684ddb6SLionel Sambuc : __begin_(nullptr), 27494684ddb6SLionel Sambuc __size_(0), 27504684ddb6SLionel Sambuc __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc())) 27514684ddb6SLionel Sambuc{ 27524684ddb6SLionel Sambuc if (__v.size() > 0) 27534684ddb6SLionel Sambuc { 27544684ddb6SLionel Sambuc allocate(__v.size()); 27554684ddb6SLionel Sambuc __construct_at_end(__v.begin(), __v.end()); 27564684ddb6SLionel Sambuc } 27574684ddb6SLionel Sambuc} 27584684ddb6SLionel Sambuc 27594684ddb6SLionel Sambuctemplate <class _Allocator> 27604684ddb6SLionel Sambucvector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a) 27614684ddb6SLionel Sambuc : __begin_(nullptr), 27624684ddb6SLionel Sambuc __size_(0), 27634684ddb6SLionel Sambuc __cap_alloc_(0, __a) 27644684ddb6SLionel Sambuc{ 27654684ddb6SLionel Sambuc if (__v.size() > 0) 27664684ddb6SLionel Sambuc { 27674684ddb6SLionel Sambuc allocate(__v.size()); 27684684ddb6SLionel Sambuc __construct_at_end(__v.begin(), __v.end()); 27694684ddb6SLionel Sambuc } 27704684ddb6SLionel Sambuc} 27714684ddb6SLionel Sambuc 27724684ddb6SLionel Sambuctemplate <class _Allocator> 27734684ddb6SLionel Sambucvector<bool, _Allocator>& 27744684ddb6SLionel Sambucvector<bool, _Allocator>::operator=(const vector& __v) 27754684ddb6SLionel Sambuc{ 27764684ddb6SLionel Sambuc if (this != &__v) 27774684ddb6SLionel Sambuc { 27784684ddb6SLionel Sambuc __copy_assign_alloc(__v); 27794684ddb6SLionel Sambuc if (__v.__size_) 27804684ddb6SLionel Sambuc { 27814684ddb6SLionel Sambuc if (__v.__size_ > capacity()) 27824684ddb6SLionel Sambuc { 27834684ddb6SLionel Sambuc deallocate(); 27844684ddb6SLionel Sambuc allocate(__v.__size_); 27854684ddb6SLionel Sambuc } 27864684ddb6SLionel Sambuc _VSTD::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_); 27874684ddb6SLionel Sambuc } 27884684ddb6SLionel Sambuc __size_ = __v.__size_; 27894684ddb6SLionel Sambuc } 27904684ddb6SLionel Sambuc return *this; 27914684ddb6SLionel Sambuc} 27924684ddb6SLionel Sambuc 27934684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 27944684ddb6SLionel Sambuc 27954684ddb6SLionel Sambuctemplate <class _Allocator> 27964684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 27974684ddb6SLionel Sambucvector<bool, _Allocator>::vector(vector&& __v) 2798*0a6a1f1dSLionel Sambuc#if _LIBCPP_STD_VER > 14 2799*0a6a1f1dSLionel Sambuc _NOEXCEPT 2800*0a6a1f1dSLionel Sambuc#else 28014684ddb6SLionel Sambuc _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) 2802*0a6a1f1dSLionel Sambuc#endif 28034684ddb6SLionel Sambuc : __begin_(__v.__begin_), 28044684ddb6SLionel Sambuc __size_(__v.__size_), 28054684ddb6SLionel Sambuc __cap_alloc_(__v.__cap_alloc_) 28064684ddb6SLionel Sambuc{ 28074684ddb6SLionel Sambuc __v.__begin_ = nullptr; 28084684ddb6SLionel Sambuc __v.__size_ = 0; 28094684ddb6SLionel Sambuc __v.__cap() = 0; 28104684ddb6SLionel Sambuc} 28114684ddb6SLionel Sambuc 28124684ddb6SLionel Sambuctemplate <class _Allocator> 28134684ddb6SLionel Sambucvector<bool, _Allocator>::vector(vector&& __v, const allocator_type& __a) 28144684ddb6SLionel Sambuc : __begin_(nullptr), 28154684ddb6SLionel Sambuc __size_(0), 28164684ddb6SLionel Sambuc __cap_alloc_(0, __a) 28174684ddb6SLionel Sambuc{ 28184684ddb6SLionel Sambuc if (__a == allocator_type(__v.__alloc())) 28194684ddb6SLionel Sambuc { 28204684ddb6SLionel Sambuc this->__begin_ = __v.__begin_; 28214684ddb6SLionel Sambuc this->__size_ = __v.__size_; 28224684ddb6SLionel Sambuc this->__cap() = __v.__cap(); 28234684ddb6SLionel Sambuc __v.__begin_ = nullptr; 28244684ddb6SLionel Sambuc __v.__cap() = __v.__size_ = 0; 28254684ddb6SLionel Sambuc } 28264684ddb6SLionel Sambuc else if (__v.size() > 0) 28274684ddb6SLionel Sambuc { 28284684ddb6SLionel Sambuc allocate(__v.size()); 28294684ddb6SLionel Sambuc __construct_at_end(__v.begin(), __v.end()); 28304684ddb6SLionel Sambuc } 28314684ddb6SLionel Sambuc} 28324684ddb6SLionel Sambuc 28334684ddb6SLionel Sambuctemplate <class _Allocator> 28344684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 28354684ddb6SLionel Sambucvector<bool, _Allocator>& 28364684ddb6SLionel Sambucvector<bool, _Allocator>::operator=(vector&& __v) 2837*0a6a1f1dSLionel Sambuc _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) 28384684ddb6SLionel Sambuc{ 28394684ddb6SLionel Sambuc __move_assign(__v, integral_constant<bool, 28404684ddb6SLionel Sambuc __storage_traits::propagate_on_container_move_assignment::value>()); 28414684ddb6SLionel Sambuc return *this; 28424684ddb6SLionel Sambuc} 28434684ddb6SLionel Sambuc 28444684ddb6SLionel Sambuctemplate <class _Allocator> 28454684ddb6SLionel Sambucvoid 28464684ddb6SLionel Sambucvector<bool, _Allocator>::__move_assign(vector& __c, false_type) 28474684ddb6SLionel Sambuc{ 28484684ddb6SLionel Sambuc if (__alloc() != __c.__alloc()) 28494684ddb6SLionel Sambuc assign(__c.begin(), __c.end()); 28504684ddb6SLionel Sambuc else 28514684ddb6SLionel Sambuc __move_assign(__c, true_type()); 28524684ddb6SLionel Sambuc} 28534684ddb6SLionel Sambuc 28544684ddb6SLionel Sambuctemplate <class _Allocator> 28554684ddb6SLionel Sambucvoid 28564684ddb6SLionel Sambucvector<bool, _Allocator>::__move_assign(vector& __c, true_type) 28574684ddb6SLionel Sambuc _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) 28584684ddb6SLionel Sambuc{ 28594684ddb6SLionel Sambuc deallocate(); 2860*0a6a1f1dSLionel Sambuc __move_assign_alloc(__c); 28614684ddb6SLionel Sambuc this->__begin_ = __c.__begin_; 28624684ddb6SLionel Sambuc this->__size_ = __c.__size_; 28634684ddb6SLionel Sambuc this->__cap() = __c.__cap(); 28644684ddb6SLionel Sambuc __c.__begin_ = nullptr; 28654684ddb6SLionel Sambuc __c.__cap() = __c.__size_ = 0; 28664684ddb6SLionel Sambuc} 28674684ddb6SLionel Sambuc 28684684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 28694684ddb6SLionel Sambuc 28704684ddb6SLionel Sambuctemplate <class _Allocator> 28714684ddb6SLionel Sambucvoid 28724684ddb6SLionel Sambucvector<bool, _Allocator>::assign(size_type __n, const value_type& __x) 28734684ddb6SLionel Sambuc{ 28744684ddb6SLionel Sambuc __size_ = 0; 28754684ddb6SLionel Sambuc if (__n > 0) 28764684ddb6SLionel Sambuc { 28774684ddb6SLionel Sambuc size_type __c = capacity(); 28784684ddb6SLionel Sambuc if (__n <= __c) 28794684ddb6SLionel Sambuc __size_ = __n; 28804684ddb6SLionel Sambuc else 28814684ddb6SLionel Sambuc { 28824684ddb6SLionel Sambuc vector __v(__alloc()); 28834684ddb6SLionel Sambuc __v.reserve(__recommend(__n)); 28844684ddb6SLionel Sambuc __v.__size_ = __n; 28854684ddb6SLionel Sambuc swap(__v); 28864684ddb6SLionel Sambuc } 28874684ddb6SLionel Sambuc _VSTD::fill_n(begin(), __n, __x); 28884684ddb6SLionel Sambuc } 28894684ddb6SLionel Sambuc} 28904684ddb6SLionel Sambuc 28914684ddb6SLionel Sambuctemplate <class _Allocator> 28924684ddb6SLionel Sambuctemplate <class _InputIterator> 28934684ddb6SLionel Sambuctypename enable_if 28944684ddb6SLionel Sambuc< 28954684ddb6SLionel Sambuc __is_input_iterator<_InputIterator>::value && 28964684ddb6SLionel Sambuc !__is_forward_iterator<_InputIterator>::value, 28974684ddb6SLionel Sambuc void 28984684ddb6SLionel Sambuc>::type 28994684ddb6SLionel Sambucvector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last) 29004684ddb6SLionel Sambuc{ 29014684ddb6SLionel Sambuc clear(); 29024684ddb6SLionel Sambuc for (; __first != __last; ++__first) 29034684ddb6SLionel Sambuc push_back(*__first); 29044684ddb6SLionel Sambuc} 29054684ddb6SLionel Sambuc 29064684ddb6SLionel Sambuctemplate <class _Allocator> 29074684ddb6SLionel Sambuctemplate <class _ForwardIterator> 29084684ddb6SLionel Sambuctypename enable_if 29094684ddb6SLionel Sambuc< 29104684ddb6SLionel Sambuc __is_forward_iterator<_ForwardIterator>::value, 29114684ddb6SLionel Sambuc void 29124684ddb6SLionel Sambuc>::type 29134684ddb6SLionel Sambucvector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) 29144684ddb6SLionel Sambuc{ 29154684ddb6SLionel Sambuc clear(); 29164684ddb6SLionel Sambuc difference_type __n = _VSTD::distance(__first, __last); 29174684ddb6SLionel Sambuc if (__n) 29184684ddb6SLionel Sambuc { 29194684ddb6SLionel Sambuc if (__n > capacity()) 29204684ddb6SLionel Sambuc { 29214684ddb6SLionel Sambuc deallocate(); 29224684ddb6SLionel Sambuc allocate(__n); 29234684ddb6SLionel Sambuc } 29244684ddb6SLionel Sambuc __construct_at_end(__first, __last); 29254684ddb6SLionel Sambuc } 29264684ddb6SLionel Sambuc} 29274684ddb6SLionel Sambuc 29284684ddb6SLionel Sambuctemplate <class _Allocator> 29294684ddb6SLionel Sambucvoid 29304684ddb6SLionel Sambucvector<bool, _Allocator>::reserve(size_type __n) 29314684ddb6SLionel Sambuc{ 29324684ddb6SLionel Sambuc if (__n > capacity()) 29334684ddb6SLionel Sambuc { 29344684ddb6SLionel Sambuc vector __v(this->__alloc()); 29354684ddb6SLionel Sambuc __v.allocate(__n); 29364684ddb6SLionel Sambuc __v.__construct_at_end(this->begin(), this->end()); 29374684ddb6SLionel Sambuc swap(__v); 29384684ddb6SLionel Sambuc __invalidate_all_iterators(); 29394684ddb6SLionel Sambuc } 29404684ddb6SLionel Sambuc} 29414684ddb6SLionel Sambuc 29424684ddb6SLionel Sambuctemplate <class _Allocator> 29434684ddb6SLionel Sambucvoid 29444684ddb6SLionel Sambucvector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT 29454684ddb6SLionel Sambuc{ 29464684ddb6SLionel Sambuc if (__external_cap_to_internal(size()) > __cap()) 29474684ddb6SLionel Sambuc { 29484684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 29494684ddb6SLionel Sambuc try 29504684ddb6SLionel Sambuc { 29514684ddb6SLionel Sambuc#endif // _LIBCPP_NO_EXCEPTIONS 29524684ddb6SLionel Sambuc vector(*this, allocator_type(__alloc())).swap(*this); 29534684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 29544684ddb6SLionel Sambuc } 29554684ddb6SLionel Sambuc catch (...) 29564684ddb6SLionel Sambuc { 29574684ddb6SLionel Sambuc } 29584684ddb6SLionel Sambuc#endif // _LIBCPP_NO_EXCEPTIONS 29594684ddb6SLionel Sambuc } 29604684ddb6SLionel Sambuc} 29614684ddb6SLionel Sambuc 29624684ddb6SLionel Sambuctemplate <class _Allocator> 29634684ddb6SLionel Sambuctypename vector<bool, _Allocator>::reference 29644684ddb6SLionel Sambucvector<bool, _Allocator>::at(size_type __n) 29654684ddb6SLionel Sambuc{ 29664684ddb6SLionel Sambuc if (__n >= size()) 29674684ddb6SLionel Sambuc this->__throw_out_of_range(); 29684684ddb6SLionel Sambuc return (*this)[__n]; 29694684ddb6SLionel Sambuc} 29704684ddb6SLionel Sambuc 29714684ddb6SLionel Sambuctemplate <class _Allocator> 29724684ddb6SLionel Sambuctypename vector<bool, _Allocator>::const_reference 29734684ddb6SLionel Sambucvector<bool, _Allocator>::at(size_type __n) const 29744684ddb6SLionel Sambuc{ 29754684ddb6SLionel Sambuc if (__n >= size()) 29764684ddb6SLionel Sambuc this->__throw_out_of_range(); 29774684ddb6SLionel Sambuc return (*this)[__n]; 29784684ddb6SLionel Sambuc} 29794684ddb6SLionel Sambuc 29804684ddb6SLionel Sambuctemplate <class _Allocator> 29814684ddb6SLionel Sambucvoid 29824684ddb6SLionel Sambucvector<bool, _Allocator>::push_back(const value_type& __x) 29834684ddb6SLionel Sambuc{ 29844684ddb6SLionel Sambuc if (this->__size_ == this->capacity()) 29854684ddb6SLionel Sambuc reserve(__recommend(this->__size_ + 1)); 29864684ddb6SLionel Sambuc ++this->__size_; 29874684ddb6SLionel Sambuc back() = __x; 29884684ddb6SLionel Sambuc} 29894684ddb6SLionel Sambuc 29904684ddb6SLionel Sambuctemplate <class _Allocator> 29914684ddb6SLionel Sambuctypename vector<bool, _Allocator>::iterator 29924684ddb6SLionel Sambucvector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x) 29934684ddb6SLionel Sambuc{ 29944684ddb6SLionel Sambuc iterator __r; 29954684ddb6SLionel Sambuc if (size() < capacity()) 29964684ddb6SLionel Sambuc { 29974684ddb6SLionel Sambuc const_iterator __old_end = end(); 29984684ddb6SLionel Sambuc ++__size_; 29994684ddb6SLionel Sambuc _VSTD::copy_backward(__position, __old_end, end()); 30004684ddb6SLionel Sambuc __r = __const_iterator_cast(__position); 30014684ddb6SLionel Sambuc } 30024684ddb6SLionel Sambuc else 30034684ddb6SLionel Sambuc { 30044684ddb6SLionel Sambuc vector __v(__alloc()); 30054684ddb6SLionel Sambuc __v.reserve(__recommend(__size_ + 1)); 30064684ddb6SLionel Sambuc __v.__size_ = __size_ + 1; 30074684ddb6SLionel Sambuc __r = _VSTD::copy(cbegin(), __position, __v.begin()); 30084684ddb6SLionel Sambuc _VSTD::copy_backward(__position, cend(), __v.end()); 30094684ddb6SLionel Sambuc swap(__v); 30104684ddb6SLionel Sambuc } 30114684ddb6SLionel Sambuc *__r = __x; 30124684ddb6SLionel Sambuc return __r; 30134684ddb6SLionel Sambuc} 30144684ddb6SLionel Sambuc 30154684ddb6SLionel Sambuctemplate <class _Allocator> 30164684ddb6SLionel Sambuctypename vector<bool, _Allocator>::iterator 30174684ddb6SLionel Sambucvector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x) 30184684ddb6SLionel Sambuc{ 30194684ddb6SLionel Sambuc iterator __r; 30204684ddb6SLionel Sambuc size_type __c = capacity(); 30214684ddb6SLionel Sambuc if (__n <= __c && size() <= __c - __n) 30224684ddb6SLionel Sambuc { 30234684ddb6SLionel Sambuc const_iterator __old_end = end(); 30244684ddb6SLionel Sambuc __size_ += __n; 30254684ddb6SLionel Sambuc _VSTD::copy_backward(__position, __old_end, end()); 30264684ddb6SLionel Sambuc __r = __const_iterator_cast(__position); 30274684ddb6SLionel Sambuc } 30284684ddb6SLionel Sambuc else 30294684ddb6SLionel Sambuc { 30304684ddb6SLionel Sambuc vector __v(__alloc()); 30314684ddb6SLionel Sambuc __v.reserve(__recommend(__size_ + __n)); 30324684ddb6SLionel Sambuc __v.__size_ = __size_ + __n; 30334684ddb6SLionel Sambuc __r = _VSTD::copy(cbegin(), __position, __v.begin()); 30344684ddb6SLionel Sambuc _VSTD::copy_backward(__position, cend(), __v.end()); 30354684ddb6SLionel Sambuc swap(__v); 30364684ddb6SLionel Sambuc } 30374684ddb6SLionel Sambuc _VSTD::fill_n(__r, __n, __x); 30384684ddb6SLionel Sambuc return __r; 30394684ddb6SLionel Sambuc} 30404684ddb6SLionel Sambuc 30414684ddb6SLionel Sambuctemplate <class _Allocator> 30424684ddb6SLionel Sambuctemplate <class _InputIterator> 30434684ddb6SLionel Sambuctypename enable_if 30444684ddb6SLionel Sambuc< 30454684ddb6SLionel Sambuc __is_input_iterator <_InputIterator>::value && 30464684ddb6SLionel Sambuc !__is_forward_iterator<_InputIterator>::value, 30474684ddb6SLionel Sambuc typename vector<bool, _Allocator>::iterator 30484684ddb6SLionel Sambuc>::type 30494684ddb6SLionel Sambucvector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last) 30504684ddb6SLionel Sambuc{ 30514684ddb6SLionel Sambuc difference_type __off = __position - begin(); 30524684ddb6SLionel Sambuc iterator __p = __const_iterator_cast(__position); 30534684ddb6SLionel Sambuc iterator __old_end = end(); 30544684ddb6SLionel Sambuc for (; size() != capacity() && __first != __last; ++__first) 30554684ddb6SLionel Sambuc { 30564684ddb6SLionel Sambuc ++this->__size_; 30574684ddb6SLionel Sambuc back() = *__first; 30584684ddb6SLionel Sambuc } 30594684ddb6SLionel Sambuc vector __v(__alloc()); 30604684ddb6SLionel Sambuc if (__first != __last) 30614684ddb6SLionel Sambuc { 30624684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 30634684ddb6SLionel Sambuc try 30644684ddb6SLionel Sambuc { 30654684ddb6SLionel Sambuc#endif // _LIBCPP_NO_EXCEPTIONS 30664684ddb6SLionel Sambuc __v.assign(__first, __last); 30674684ddb6SLionel Sambuc difference_type __old_size = static_cast<difference_type>(__old_end - begin()); 30684684ddb6SLionel Sambuc difference_type __old_p = __p - begin(); 30694684ddb6SLionel Sambuc reserve(__recommend(size() + __v.size())); 30704684ddb6SLionel Sambuc __p = begin() + __old_p; 30714684ddb6SLionel Sambuc __old_end = begin() + __old_size; 30724684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 30734684ddb6SLionel Sambuc } 30744684ddb6SLionel Sambuc catch (...) 30754684ddb6SLionel Sambuc { 30764684ddb6SLionel Sambuc erase(__old_end, end()); 30774684ddb6SLionel Sambuc throw; 30784684ddb6SLionel Sambuc } 30794684ddb6SLionel Sambuc#endif // _LIBCPP_NO_EXCEPTIONS 30804684ddb6SLionel Sambuc } 30814684ddb6SLionel Sambuc __p = _VSTD::rotate(__p, __old_end, end()); 30824684ddb6SLionel Sambuc insert(__p, __v.begin(), __v.end()); 30834684ddb6SLionel Sambuc return begin() + __off; 30844684ddb6SLionel Sambuc} 30854684ddb6SLionel Sambuc 30864684ddb6SLionel Sambuctemplate <class _Allocator> 30874684ddb6SLionel Sambuctemplate <class _ForwardIterator> 30884684ddb6SLionel Sambuctypename enable_if 30894684ddb6SLionel Sambuc< 30904684ddb6SLionel Sambuc __is_forward_iterator<_ForwardIterator>::value, 30914684ddb6SLionel Sambuc typename vector<bool, _Allocator>::iterator 30924684ddb6SLionel Sambuc>::type 30934684ddb6SLionel Sambucvector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last) 30944684ddb6SLionel Sambuc{ 30954684ddb6SLionel Sambuc difference_type __n = _VSTD::distance(__first, __last); 30964684ddb6SLionel Sambuc iterator __r; 30974684ddb6SLionel Sambuc size_type __c = capacity(); 30984684ddb6SLionel Sambuc if (__n <= __c && size() <= __c - __n) 30994684ddb6SLionel Sambuc { 31004684ddb6SLionel Sambuc const_iterator __old_end = end(); 31014684ddb6SLionel Sambuc __size_ += __n; 31024684ddb6SLionel Sambuc _VSTD::copy_backward(__position, __old_end, end()); 31034684ddb6SLionel Sambuc __r = __const_iterator_cast(__position); 31044684ddb6SLionel Sambuc } 31054684ddb6SLionel Sambuc else 31064684ddb6SLionel Sambuc { 31074684ddb6SLionel Sambuc vector __v(__alloc()); 31084684ddb6SLionel Sambuc __v.reserve(__recommend(__size_ + __n)); 31094684ddb6SLionel Sambuc __v.__size_ = __size_ + __n; 31104684ddb6SLionel Sambuc __r = _VSTD::copy(cbegin(), __position, __v.begin()); 31114684ddb6SLionel Sambuc _VSTD::copy_backward(__position, cend(), __v.end()); 31124684ddb6SLionel Sambuc swap(__v); 31134684ddb6SLionel Sambuc } 31144684ddb6SLionel Sambuc _VSTD::copy(__first, __last, __r); 31154684ddb6SLionel Sambuc return __r; 31164684ddb6SLionel Sambuc} 31174684ddb6SLionel Sambuc 31184684ddb6SLionel Sambuctemplate <class _Allocator> 31194684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 31204684ddb6SLionel Sambuctypename vector<bool, _Allocator>::iterator 31214684ddb6SLionel Sambucvector<bool, _Allocator>::erase(const_iterator __position) 31224684ddb6SLionel Sambuc{ 31234684ddb6SLionel Sambuc iterator __r = __const_iterator_cast(__position); 31244684ddb6SLionel Sambuc _VSTD::copy(__position + 1, this->cend(), __r); 31254684ddb6SLionel Sambuc --__size_; 31264684ddb6SLionel Sambuc return __r; 31274684ddb6SLionel Sambuc} 31284684ddb6SLionel Sambuc 31294684ddb6SLionel Sambuctemplate <class _Allocator> 31304684ddb6SLionel Sambuctypename vector<bool, _Allocator>::iterator 31314684ddb6SLionel Sambucvector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last) 31324684ddb6SLionel Sambuc{ 31334684ddb6SLionel Sambuc iterator __r = __const_iterator_cast(__first); 31344684ddb6SLionel Sambuc difference_type __d = __last - __first; 31354684ddb6SLionel Sambuc _VSTD::copy(__last, this->cend(), __r); 31364684ddb6SLionel Sambuc __size_ -= __d; 31374684ddb6SLionel Sambuc return __r; 31384684ddb6SLionel Sambuc} 31394684ddb6SLionel Sambuc 31404684ddb6SLionel Sambuctemplate <class _Allocator> 31414684ddb6SLionel Sambucvoid 31424684ddb6SLionel Sambucvector<bool, _Allocator>::swap(vector& __x) 3143*0a6a1f1dSLionel Sambuc#if _LIBCPP_STD_VER >= 14 3144*0a6a1f1dSLionel Sambuc _NOEXCEPT 3145*0a6a1f1dSLionel Sambuc#else 31464684ddb6SLionel Sambuc _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || 31474684ddb6SLionel Sambuc __is_nothrow_swappable<allocator_type>::value) 3148*0a6a1f1dSLionel Sambuc#endif 31494684ddb6SLionel Sambuc{ 31504684ddb6SLionel Sambuc _VSTD::swap(this->__begin_, __x.__begin_); 31514684ddb6SLionel Sambuc _VSTD::swap(this->__size_, __x.__size_); 31524684ddb6SLionel Sambuc _VSTD::swap(this->__cap(), __x.__cap()); 3153*0a6a1f1dSLionel Sambuc __swap_allocator(this->__alloc(), __x.__alloc(), 3154*0a6a1f1dSLionel Sambuc integral_constant<bool, __alloc_traits::propagate_on_container_swap::value>()); 31554684ddb6SLionel Sambuc} 31564684ddb6SLionel Sambuc 31574684ddb6SLionel Sambuctemplate <class _Allocator> 31584684ddb6SLionel Sambucvoid 31594684ddb6SLionel Sambucvector<bool, _Allocator>::resize(size_type __sz, value_type __x) 31604684ddb6SLionel Sambuc{ 31614684ddb6SLionel Sambuc size_type __cs = size(); 31624684ddb6SLionel Sambuc if (__cs < __sz) 31634684ddb6SLionel Sambuc { 31644684ddb6SLionel Sambuc iterator __r; 31654684ddb6SLionel Sambuc size_type __c = capacity(); 31664684ddb6SLionel Sambuc size_type __n = __sz - __cs; 31674684ddb6SLionel Sambuc if (__n <= __c && __cs <= __c - __n) 31684684ddb6SLionel Sambuc { 31694684ddb6SLionel Sambuc __r = end(); 31704684ddb6SLionel Sambuc __size_ += __n; 31714684ddb6SLionel Sambuc } 31724684ddb6SLionel Sambuc else 31734684ddb6SLionel Sambuc { 31744684ddb6SLionel Sambuc vector __v(__alloc()); 31754684ddb6SLionel Sambuc __v.reserve(__recommend(__size_ + __n)); 31764684ddb6SLionel Sambuc __v.__size_ = __size_ + __n; 31774684ddb6SLionel Sambuc __r = _VSTD::copy(cbegin(), cend(), __v.begin()); 31784684ddb6SLionel Sambuc swap(__v); 31794684ddb6SLionel Sambuc } 31804684ddb6SLionel Sambuc _VSTD::fill_n(__r, __n, __x); 31814684ddb6SLionel Sambuc } 31824684ddb6SLionel Sambuc else 31834684ddb6SLionel Sambuc __size_ = __sz; 31844684ddb6SLionel Sambuc} 31854684ddb6SLionel Sambuc 31864684ddb6SLionel Sambuctemplate <class _Allocator> 31874684ddb6SLionel Sambucvoid 31884684ddb6SLionel Sambucvector<bool, _Allocator>::flip() _NOEXCEPT 31894684ddb6SLionel Sambuc{ 31904684ddb6SLionel Sambuc // do middle whole words 31914684ddb6SLionel Sambuc size_type __n = __size_; 31924684ddb6SLionel Sambuc __storage_pointer __p = __begin_; 31934684ddb6SLionel Sambuc for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) 31944684ddb6SLionel Sambuc *__p = ~*__p; 31954684ddb6SLionel Sambuc // do last partial word 31964684ddb6SLionel Sambuc if (__n > 0) 31974684ddb6SLionel Sambuc { 31984684ddb6SLionel Sambuc __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); 31994684ddb6SLionel Sambuc __storage_type __b = *__p & __m; 32004684ddb6SLionel Sambuc *__p &= ~__m; 32014684ddb6SLionel Sambuc *__p |= ~__b & __m; 32024684ddb6SLionel Sambuc } 32034684ddb6SLionel Sambuc} 32044684ddb6SLionel Sambuc 32054684ddb6SLionel Sambuctemplate <class _Allocator> 32064684ddb6SLionel Sambucbool 32074684ddb6SLionel Sambucvector<bool, _Allocator>::__invariants() const 32084684ddb6SLionel Sambuc{ 32094684ddb6SLionel Sambuc if (this->__begin_ == nullptr) 32104684ddb6SLionel Sambuc { 32114684ddb6SLionel Sambuc if (this->__size_ != 0 || this->__cap() != 0) 32124684ddb6SLionel Sambuc return false; 32134684ddb6SLionel Sambuc } 32144684ddb6SLionel Sambuc else 32154684ddb6SLionel Sambuc { 32164684ddb6SLionel Sambuc if (this->__cap() == 0) 32174684ddb6SLionel Sambuc return false; 32184684ddb6SLionel Sambuc if (this->__size_ > this->capacity()) 32194684ddb6SLionel Sambuc return false; 32204684ddb6SLionel Sambuc } 32214684ddb6SLionel Sambuc return true; 32224684ddb6SLionel Sambuc} 32234684ddb6SLionel Sambuc 32244684ddb6SLionel Sambuctemplate <class _Allocator> 32254684ddb6SLionel Sambucsize_t 32264684ddb6SLionel Sambucvector<bool, _Allocator>::__hash_code() const _NOEXCEPT 32274684ddb6SLionel Sambuc{ 32284684ddb6SLionel Sambuc size_t __h = 0; 32294684ddb6SLionel Sambuc // do middle whole words 32304684ddb6SLionel Sambuc size_type __n = __size_; 32314684ddb6SLionel Sambuc __storage_pointer __p = __begin_; 32324684ddb6SLionel Sambuc for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) 32334684ddb6SLionel Sambuc __h ^= *__p; 32344684ddb6SLionel Sambuc // do last partial word 32354684ddb6SLionel Sambuc if (__n > 0) 32364684ddb6SLionel Sambuc { 32374684ddb6SLionel Sambuc const __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); 32384684ddb6SLionel Sambuc __h ^= *__p & __m; 32394684ddb6SLionel Sambuc } 32404684ddb6SLionel Sambuc return __h; 32414684ddb6SLionel Sambuc} 32424684ddb6SLionel Sambuc 32434684ddb6SLionel Sambuctemplate <class _Allocator> 32444684ddb6SLionel Sambucstruct _LIBCPP_TYPE_VIS_ONLY hash<vector<bool, _Allocator> > 32454684ddb6SLionel Sambuc : public unary_function<vector<bool, _Allocator>, size_t> 32464684ddb6SLionel Sambuc{ 32474684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 32484684ddb6SLionel Sambuc size_t operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT 32494684ddb6SLionel Sambuc {return __vec.__hash_code();} 32504684ddb6SLionel Sambuc}; 32514684ddb6SLionel Sambuc 32524684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 32534684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 32544684ddb6SLionel Sambucbool 32554684ddb6SLionel Sambucoperator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) 32564684ddb6SLionel Sambuc{ 32574684ddb6SLionel Sambuc const typename vector<_Tp, _Allocator>::size_type __sz = __x.size(); 32584684ddb6SLionel Sambuc return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin()); 32594684ddb6SLionel Sambuc} 32604684ddb6SLionel Sambuc 32614684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 32624684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 32634684ddb6SLionel Sambucbool 32644684ddb6SLionel Sambucoperator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) 32654684ddb6SLionel Sambuc{ 32664684ddb6SLionel Sambuc return !(__x == __y); 32674684ddb6SLionel Sambuc} 32684684ddb6SLionel Sambuc 32694684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 32704684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 32714684ddb6SLionel Sambucbool 32724684ddb6SLionel Sambucoperator< (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) 32734684ddb6SLionel Sambuc{ 32744684ddb6SLionel Sambuc return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); 32754684ddb6SLionel Sambuc} 32764684ddb6SLionel Sambuc 32774684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 32784684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 32794684ddb6SLionel Sambucbool 32804684ddb6SLionel Sambucoperator> (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) 32814684ddb6SLionel Sambuc{ 32824684ddb6SLionel Sambuc return __y < __x; 32834684ddb6SLionel Sambuc} 32844684ddb6SLionel Sambuc 32854684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 32864684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 32874684ddb6SLionel Sambucbool 32884684ddb6SLionel Sambucoperator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) 32894684ddb6SLionel Sambuc{ 32904684ddb6SLionel Sambuc return !(__x < __y); 32914684ddb6SLionel Sambuc} 32924684ddb6SLionel Sambuc 32934684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 32944684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 32954684ddb6SLionel Sambucbool 32964684ddb6SLionel Sambucoperator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) 32974684ddb6SLionel Sambuc{ 32984684ddb6SLionel Sambuc return !(__y < __x); 32994684ddb6SLionel Sambuc} 33004684ddb6SLionel Sambuc 33014684ddb6SLionel Sambuctemplate <class _Tp, class _Allocator> 33024684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 33034684ddb6SLionel Sambucvoid 33044684ddb6SLionel Sambucswap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y) 33054684ddb6SLionel Sambuc _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) 33064684ddb6SLionel Sambuc{ 33074684ddb6SLionel Sambuc __x.swap(__y); 33084684ddb6SLionel Sambuc} 33094684ddb6SLionel Sambuc 33104684ddb6SLionel Sambuc_LIBCPP_END_NAMESPACE_STD 33114684ddb6SLionel Sambuc 33124684ddb6SLionel Sambuc#endif // _LIBCPP_VECTOR 3313