10b57cec5SDimitry Andric// -*- C++ -*- 2349cc55cSDimitry Andric//===----------------------------------------------------------------------===// 30b57cec5SDimitry Andric// 40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 70b57cec5SDimitry Andric// 80b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 90b57cec5SDimitry Andric 100b57cec5SDimitry Andric#ifndef _LIBCPP_VECTOR 110b57cec5SDimitry Andric#define _LIBCPP_VECTOR 120b57cec5SDimitry Andric 130b57cec5SDimitry Andric/* 140b57cec5SDimitry Andric vector synopsis 150b57cec5SDimitry Andric 160b57cec5SDimitry Andricnamespace std 170b57cec5SDimitry Andric{ 180b57cec5SDimitry Andric 190b57cec5SDimitry Andrictemplate <class T, class Allocator = allocator<T> > 200b57cec5SDimitry Andricclass vector 210b57cec5SDimitry Andric{ 220b57cec5SDimitry Andricpublic: 230b57cec5SDimitry Andric typedef T value_type; 240b57cec5SDimitry Andric typedef Allocator allocator_type; 250b57cec5SDimitry Andric typedef typename allocator_type::reference reference; 260b57cec5SDimitry Andric typedef typename allocator_type::const_reference const_reference; 270b57cec5SDimitry Andric typedef implementation-defined iterator; 280b57cec5SDimitry Andric typedef implementation-defined const_iterator; 290b57cec5SDimitry Andric typedef typename allocator_type::size_type size_type; 300b57cec5SDimitry Andric typedef typename allocator_type::difference_type difference_type; 310b57cec5SDimitry Andric typedef typename allocator_type::pointer pointer; 320b57cec5SDimitry Andric typedef typename allocator_type::const_pointer const_pointer; 330b57cec5SDimitry Andric typedef std::reverse_iterator<iterator> reverse_iterator; 340b57cec5SDimitry Andric typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 350b57cec5SDimitry Andric 360b57cec5SDimitry Andric vector() 370b57cec5SDimitry Andric noexcept(is_nothrow_default_constructible<allocator_type>::value); 380b57cec5SDimitry Andric explicit vector(const allocator_type&); 390b57cec5SDimitry Andric explicit vector(size_type n); 400b57cec5SDimitry Andric explicit vector(size_type n, const allocator_type&); // C++14 410b57cec5SDimitry Andric vector(size_type n, const value_type& value, const allocator_type& = allocator_type()); 420b57cec5SDimitry Andric template <class InputIterator> 430b57cec5SDimitry Andric vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type()); 440b57cec5SDimitry Andric vector(const vector& x); 450b57cec5SDimitry Andric vector(vector&& x) 460b57cec5SDimitry Andric noexcept(is_nothrow_move_constructible<allocator_type>::value); 470b57cec5SDimitry Andric vector(initializer_list<value_type> il); 480b57cec5SDimitry Andric vector(initializer_list<value_type> il, const allocator_type& a); 490b57cec5SDimitry Andric ~vector(); 500b57cec5SDimitry Andric vector& operator=(const vector& x); 510b57cec5SDimitry Andric vector& operator=(vector&& x) 520b57cec5SDimitry Andric noexcept( 530b57cec5SDimitry Andric allocator_type::propagate_on_container_move_assignment::value || 540b57cec5SDimitry Andric allocator_type::is_always_equal::value); // C++17 550b57cec5SDimitry Andric vector& operator=(initializer_list<value_type> il); 560b57cec5SDimitry Andric template <class InputIterator> 570b57cec5SDimitry Andric void assign(InputIterator first, InputIterator last); 580b57cec5SDimitry Andric void assign(size_type n, const value_type& u); 590b57cec5SDimitry Andric void assign(initializer_list<value_type> il); 600b57cec5SDimitry Andric 610b57cec5SDimitry Andric allocator_type get_allocator() const noexcept; 620b57cec5SDimitry Andric 630b57cec5SDimitry Andric iterator begin() noexcept; 640b57cec5SDimitry Andric const_iterator begin() const noexcept; 650b57cec5SDimitry Andric iterator end() noexcept; 660b57cec5SDimitry Andric const_iterator end() const noexcept; 670b57cec5SDimitry Andric 680b57cec5SDimitry Andric reverse_iterator rbegin() noexcept; 690b57cec5SDimitry Andric const_reverse_iterator rbegin() const noexcept; 700b57cec5SDimitry Andric reverse_iterator rend() noexcept; 710b57cec5SDimitry Andric const_reverse_iterator rend() const noexcept; 720b57cec5SDimitry Andric 730b57cec5SDimitry Andric const_iterator cbegin() const noexcept; 740b57cec5SDimitry Andric const_iterator cend() const noexcept; 750b57cec5SDimitry Andric const_reverse_iterator crbegin() const noexcept; 760b57cec5SDimitry Andric const_reverse_iterator crend() const noexcept; 770b57cec5SDimitry Andric 780b57cec5SDimitry Andric size_type size() const noexcept; 790b57cec5SDimitry Andric size_type max_size() const noexcept; 800b57cec5SDimitry Andric size_type capacity() const noexcept; 810b57cec5SDimitry Andric bool empty() const noexcept; 820b57cec5SDimitry Andric void reserve(size_type n); 830b57cec5SDimitry Andric void shrink_to_fit() noexcept; 840b57cec5SDimitry Andric 850b57cec5SDimitry Andric reference operator[](size_type n); 860b57cec5SDimitry Andric const_reference operator[](size_type n) const; 870b57cec5SDimitry Andric reference at(size_type n); 880b57cec5SDimitry Andric const_reference at(size_type n) const; 890b57cec5SDimitry Andric 900b57cec5SDimitry Andric reference front(); 910b57cec5SDimitry Andric const_reference front() const; 920b57cec5SDimitry Andric reference back(); 930b57cec5SDimitry Andric const_reference back() const; 940b57cec5SDimitry Andric 950b57cec5SDimitry Andric value_type* data() noexcept; 960b57cec5SDimitry Andric const value_type* data() const noexcept; 970b57cec5SDimitry Andric 980b57cec5SDimitry Andric void push_back(const value_type& x); 990b57cec5SDimitry Andric void push_back(value_type&& x); 1000b57cec5SDimitry Andric template <class... Args> 1010b57cec5SDimitry Andric reference emplace_back(Args&&... args); // reference in C++17 1020b57cec5SDimitry Andric void pop_back(); 1030b57cec5SDimitry Andric 1040b57cec5SDimitry Andric template <class... Args> iterator emplace(const_iterator position, Args&&... args); 1050b57cec5SDimitry Andric iterator insert(const_iterator position, const value_type& x); 1060b57cec5SDimitry Andric iterator insert(const_iterator position, value_type&& x); 1070b57cec5SDimitry Andric iterator insert(const_iterator position, size_type n, const value_type& x); 1080b57cec5SDimitry Andric template <class InputIterator> 1090b57cec5SDimitry Andric iterator insert(const_iterator position, InputIterator first, InputIterator last); 1100b57cec5SDimitry Andric iterator insert(const_iterator position, initializer_list<value_type> il); 1110b57cec5SDimitry Andric 1120b57cec5SDimitry Andric iterator erase(const_iterator position); 1130b57cec5SDimitry Andric iterator erase(const_iterator first, const_iterator last); 1140b57cec5SDimitry Andric 1150b57cec5SDimitry Andric void clear() noexcept; 1160b57cec5SDimitry Andric 1170b57cec5SDimitry Andric void resize(size_type sz); 1180b57cec5SDimitry Andric void resize(size_type sz, const value_type& c); 1190b57cec5SDimitry Andric 1200b57cec5SDimitry Andric void swap(vector&) 1210b57cec5SDimitry Andric noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value || 1220b57cec5SDimitry Andric allocator_traits<allocator_type>::is_always_equal::value); // C++17 1230b57cec5SDimitry Andric 1240b57cec5SDimitry Andric bool __invariants() const; 1250b57cec5SDimitry Andric}; 1260b57cec5SDimitry Andric 1270b57cec5SDimitry Andrictemplate <class Allocator = allocator<T> > 1280b57cec5SDimitry Andricclass vector<bool, Allocator> 1290b57cec5SDimitry Andric{ 1300b57cec5SDimitry Andricpublic: 1310b57cec5SDimitry Andric typedef bool value_type; 1320b57cec5SDimitry Andric typedef Allocator allocator_type; 1330b57cec5SDimitry Andric typedef implementation-defined iterator; 1340b57cec5SDimitry Andric typedef implementation-defined const_iterator; 1350b57cec5SDimitry Andric typedef typename allocator_type::size_type size_type; 1360b57cec5SDimitry Andric typedef typename allocator_type::difference_type difference_type; 1370b57cec5SDimitry Andric typedef iterator pointer; 1380b57cec5SDimitry Andric typedef const_iterator const_pointer; 1390b57cec5SDimitry Andric typedef std::reverse_iterator<iterator> reverse_iterator; 1400b57cec5SDimitry Andric typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 1410b57cec5SDimitry Andric 1420b57cec5SDimitry Andric class reference 1430b57cec5SDimitry Andric { 1440b57cec5SDimitry Andric public: 1450b57cec5SDimitry Andric reference(const reference&) noexcept; 1460b57cec5SDimitry Andric operator bool() const noexcept; 147fe6060f1SDimitry Andric reference& operator=(bool x) noexcept; 1480b57cec5SDimitry Andric reference& operator=(const reference& x) noexcept; 1490b57cec5SDimitry Andric iterator operator&() const noexcept; 1500b57cec5SDimitry Andric void flip() noexcept; 1510b57cec5SDimitry Andric }; 1520b57cec5SDimitry Andric 1530b57cec5SDimitry Andric class const_reference 1540b57cec5SDimitry Andric { 1550b57cec5SDimitry Andric public: 1560b57cec5SDimitry Andric const_reference(const reference&) noexcept; 1570b57cec5SDimitry Andric operator bool() const noexcept; 1580b57cec5SDimitry Andric const_iterator operator&() const noexcept; 1590b57cec5SDimitry Andric }; 1600b57cec5SDimitry Andric 1610b57cec5SDimitry Andric vector() 1620b57cec5SDimitry Andric noexcept(is_nothrow_default_constructible<allocator_type>::value); 1630b57cec5SDimitry Andric explicit vector(const allocator_type&); 1640b57cec5SDimitry Andric explicit vector(size_type n, const allocator_type& a = allocator_type()); // C++14 1650b57cec5SDimitry Andric vector(size_type n, const value_type& value, const allocator_type& = allocator_type()); 1660b57cec5SDimitry Andric template <class InputIterator> 1670b57cec5SDimitry Andric vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type()); 1680b57cec5SDimitry Andric vector(const vector& x); 1690b57cec5SDimitry Andric vector(vector&& x) 1700b57cec5SDimitry Andric noexcept(is_nothrow_move_constructible<allocator_type>::value); 1710b57cec5SDimitry Andric vector(initializer_list<value_type> il); 1720b57cec5SDimitry Andric vector(initializer_list<value_type> il, const allocator_type& a); 1730b57cec5SDimitry Andric ~vector(); 1740b57cec5SDimitry Andric vector& operator=(const vector& x); 1750b57cec5SDimitry Andric vector& operator=(vector&& x) 1760b57cec5SDimitry Andric noexcept( 1770b57cec5SDimitry Andric allocator_type::propagate_on_container_move_assignment::value || 1780b57cec5SDimitry Andric allocator_type::is_always_equal::value); // C++17 1790b57cec5SDimitry Andric vector& operator=(initializer_list<value_type> il); 1800b57cec5SDimitry Andric template <class InputIterator> 1810b57cec5SDimitry Andric void assign(InputIterator first, InputIterator last); 1820b57cec5SDimitry Andric void assign(size_type n, const value_type& u); 1830b57cec5SDimitry Andric void assign(initializer_list<value_type> il); 1840b57cec5SDimitry Andric 1850b57cec5SDimitry Andric allocator_type get_allocator() const noexcept; 1860b57cec5SDimitry Andric 1870b57cec5SDimitry Andric iterator begin() noexcept; 1880b57cec5SDimitry Andric const_iterator begin() const noexcept; 1890b57cec5SDimitry Andric iterator end() noexcept; 1900b57cec5SDimitry Andric const_iterator end() const noexcept; 1910b57cec5SDimitry Andric 1920b57cec5SDimitry Andric reverse_iterator rbegin() noexcept; 1930b57cec5SDimitry Andric const_reverse_iterator rbegin() const noexcept; 1940b57cec5SDimitry Andric reverse_iterator rend() noexcept; 1950b57cec5SDimitry Andric const_reverse_iterator rend() const noexcept; 1960b57cec5SDimitry Andric 1970b57cec5SDimitry Andric const_iterator cbegin() const noexcept; 1980b57cec5SDimitry Andric const_iterator cend() const noexcept; 1990b57cec5SDimitry Andric const_reverse_iterator crbegin() const noexcept; 2000b57cec5SDimitry Andric const_reverse_iterator crend() const noexcept; 2010b57cec5SDimitry Andric 2020b57cec5SDimitry Andric size_type size() const noexcept; 2030b57cec5SDimitry Andric size_type max_size() const noexcept; 2040b57cec5SDimitry Andric size_type capacity() const noexcept; 2050b57cec5SDimitry Andric bool empty() const noexcept; 2060b57cec5SDimitry Andric void reserve(size_type n); 2070b57cec5SDimitry Andric void shrink_to_fit() noexcept; 2080b57cec5SDimitry Andric 2090b57cec5SDimitry Andric reference operator[](size_type n); 2100b57cec5SDimitry Andric const_reference operator[](size_type n) const; 2110b57cec5SDimitry Andric reference at(size_type n); 2120b57cec5SDimitry Andric const_reference at(size_type n) const; 2130b57cec5SDimitry Andric 2140b57cec5SDimitry Andric reference front(); 2150b57cec5SDimitry Andric const_reference front() const; 2160b57cec5SDimitry Andric reference back(); 2170b57cec5SDimitry Andric const_reference back() const; 2180b57cec5SDimitry Andric 2190b57cec5SDimitry Andric void push_back(const value_type& x); 2200b57cec5SDimitry Andric template <class... Args> reference emplace_back(Args&&... args); // C++14; reference in C++17 2210b57cec5SDimitry Andric void pop_back(); 2220b57cec5SDimitry Andric 2230b57cec5SDimitry Andric template <class... Args> iterator emplace(const_iterator position, Args&&... args); // C++14 2240b57cec5SDimitry Andric iterator insert(const_iterator position, const value_type& x); 2250b57cec5SDimitry Andric iterator insert(const_iterator position, size_type n, const value_type& x); 2260b57cec5SDimitry Andric template <class InputIterator> 2270b57cec5SDimitry Andric iterator insert(const_iterator position, InputIterator first, InputIterator last); 2280b57cec5SDimitry Andric iterator insert(const_iterator position, initializer_list<value_type> il); 2290b57cec5SDimitry Andric 2300b57cec5SDimitry Andric iterator erase(const_iterator position); 2310b57cec5SDimitry Andric iterator erase(const_iterator first, const_iterator last); 2320b57cec5SDimitry Andric 2330b57cec5SDimitry Andric void clear() noexcept; 2340b57cec5SDimitry Andric 2350b57cec5SDimitry Andric void resize(size_type sz); 2360b57cec5SDimitry Andric void resize(size_type sz, value_type x); 2370b57cec5SDimitry Andric 2380b57cec5SDimitry Andric void swap(vector&) 2390b57cec5SDimitry Andric noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value || 2400b57cec5SDimitry Andric allocator_traits<allocator_type>::is_always_equal::value); // C++17 2410b57cec5SDimitry Andric void flip() noexcept; 2420b57cec5SDimitry Andric 2430b57cec5SDimitry Andric bool __invariants() const; 2440b57cec5SDimitry Andric}; 2450b57cec5SDimitry Andric 2460b57cec5SDimitry Andrictemplate <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>> 2470b57cec5SDimitry Andric vector(InputIterator, InputIterator, Allocator = Allocator()) 248349cc55cSDimitry Andric -> vector<typename iterator_traits<InputIterator>::value_type, Allocator>; // C++17 2490b57cec5SDimitry Andric 2500b57cec5SDimitry Andrictemplate <class Allocator> struct hash<std::vector<bool, Allocator>>; 2510b57cec5SDimitry Andric 2520b57cec5SDimitry Andrictemplate <class T, class Allocator> bool operator==(const vector<T,Allocator>& x, const vector<T,Allocator>& y); 2530b57cec5SDimitry Andrictemplate <class T, class Allocator> bool operator< (const vector<T,Allocator>& x, const vector<T,Allocator>& y); 2540b57cec5SDimitry Andrictemplate <class T, class Allocator> bool operator!=(const vector<T,Allocator>& x, const vector<T,Allocator>& y); 2550b57cec5SDimitry Andrictemplate <class T, class Allocator> bool operator> (const vector<T,Allocator>& x, const vector<T,Allocator>& y); 2560b57cec5SDimitry Andrictemplate <class T, class Allocator> bool operator>=(const vector<T,Allocator>& x, const vector<T,Allocator>& y); 2570b57cec5SDimitry Andrictemplate <class T, class Allocator> bool operator<=(const vector<T,Allocator>& x, const vector<T,Allocator>& y); 2580b57cec5SDimitry Andric 2590b57cec5SDimitry Andrictemplate <class T, class Allocator> 2600b57cec5SDimitry Andricvoid swap(vector<T,Allocator>& x, vector<T,Allocator>& y) 2610b57cec5SDimitry Andric noexcept(noexcept(x.swap(y))); 2620b57cec5SDimitry Andric 2630b57cec5SDimitry Andrictemplate <class T, class Allocator, class U> 2645ffd83dbSDimitry Andrictypename vector<T, Allocator>::size_type 2655ffd83dbSDimitry Andricerase(vector<T, Allocator>& c, const U& value); // C++20 2660b57cec5SDimitry Andrictemplate <class T, class Allocator, class Predicate> 2675ffd83dbSDimitry Andrictypename vector<T, Allocator>::size_type 2685ffd83dbSDimitry Andricerase_if(vector<T, Allocator>& c, Predicate pred); // C++20 2690b57cec5SDimitry Andric 2700b57cec5SDimitry Andric} // std 2710b57cec5SDimitry Andric 2720b57cec5SDimitry Andric*/ 2730b57cec5SDimitry Andric 274*81ad6265SDimitry Andric#include <__algorithm/copy.h> 275*81ad6265SDimitry Andric#include <__algorithm/equal.h> 276*81ad6265SDimitry Andric#include <__algorithm/fill_n.h> 277*81ad6265SDimitry Andric#include <__algorithm/lexicographical_compare.h> 278*81ad6265SDimitry Andric#include <__algorithm/remove.h> 279*81ad6265SDimitry Andric#include <__algorithm/remove_if.h> 280*81ad6265SDimitry Andric#include <__algorithm/rotate.h> 281*81ad6265SDimitry Andric#include <__algorithm/unwrap_iter.h> 282*81ad6265SDimitry Andric#include <__assert> // all public C++ headers provide the assertion handler 2830b57cec5SDimitry Andric#include <__bit_reference> 28404eeddc0SDimitry Andric#include <__config> 285fe6060f1SDimitry Andric#include <__debug> 286*81ad6265SDimitry Andric#include <__format/enable_insertable.h> 287*81ad6265SDimitry Andric#include <__functional/hash.h> 288*81ad6265SDimitry Andric#include <__functional/unary_function.h> 289*81ad6265SDimitry Andric#include <__iterator/advance.h> 290349cc55cSDimitry Andric#include <__iterator/iterator_traits.h> 291*81ad6265SDimitry Andric#include <__iterator/reverse_iterator.h> 292fe6060f1SDimitry Andric#include <__iterator/wrap_iter.h> 293*81ad6265SDimitry Andric#include <__memory/allocate_at_least.h> 294fe6060f1SDimitry Andric#include <__split_buffer> 295fe6060f1SDimitry Andric#include <__utility/forward.h> 296*81ad6265SDimitry Andric#include <__utility/move.h> 297*81ad6265SDimitry Andric#include <__utility/swap.h> 2980b57cec5SDimitry Andric#include <climits> 29969ade1e0SDimitry Andric#include <cstdlib> 300fe6060f1SDimitry Andric#include <cstring> 301fe6060f1SDimitry Andric#include <iosfwd> // for forward declaration of vector 302fe6060f1SDimitry Andric#include <limits> 3030b57cec5SDimitry Andric#include <memory> 3040b57cec5SDimitry Andric#include <stdexcept> 305fe6060f1SDimitry Andric#include <type_traits> 3060b57cec5SDimitry Andric#include <version> 3070b57cec5SDimitry Andric 308*81ad6265SDimitry Andric#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES 309*81ad6265SDimitry Andric# include <algorithm> 310*81ad6265SDimitry Andric# include <typeinfo> 311*81ad6265SDimitry Andric# include <utility> 312*81ad6265SDimitry Andric#endif 313*81ad6265SDimitry Andric 314*81ad6265SDimitry Andric// standard-mandated includes 315*81ad6265SDimitry Andric 316*81ad6265SDimitry Andric// [iterator.range] 317*81ad6265SDimitry Andric#include <__iterator/access.h> 318*81ad6265SDimitry Andric#include <__iterator/data.h> 319*81ad6265SDimitry Andric#include <__iterator/empty.h> 320*81ad6265SDimitry Andric#include <__iterator/reverse_access.h> 321*81ad6265SDimitry Andric#include <__iterator/size.h> 322*81ad6265SDimitry Andric 323*81ad6265SDimitry Andric// [vector.syn] 324*81ad6265SDimitry Andric#include <compare> 325*81ad6265SDimitry Andric#include <initializer_list> 326*81ad6265SDimitry Andric 3270b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 3280b57cec5SDimitry Andric# pragma GCC system_header 3290b57cec5SDimitry Andric#endif 3300b57cec5SDimitry Andric 3310b57cec5SDimitry Andric_LIBCPP_PUSH_MACROS 3320b57cec5SDimitry Andric#include <__undef_macros> 3330b57cec5SDimitry Andric 3340b57cec5SDimitry Andric 3350b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD 3360b57cec5SDimitry Andric 3370b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator /* = allocator<_Tp> */> 3380b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS vector 3390b57cec5SDimitry Andric{ 3400b57cec5SDimitry Andricprivate: 3410b57cec5SDimitry Andric typedef allocator<_Tp> __default_allocator_type; 3420b57cec5SDimitry Andricpublic: 3430b57cec5SDimitry Andric typedef vector __self; 3440b57cec5SDimitry Andric typedef _Tp value_type; 3450b57cec5SDimitry Andric typedef _Allocator allocator_type; 346349cc55cSDimitry Andric typedef allocator_traits<allocator_type> __alloc_traits; 347349cc55cSDimitry Andric typedef value_type& reference; 348349cc55cSDimitry Andric typedef const value_type& const_reference; 3494824e7fdSDimitry Andric typedef typename __alloc_traits::size_type size_type; 350349cc55cSDimitry Andric typedef typename __alloc_traits::difference_type difference_type; 351349cc55cSDimitry Andric typedef typename __alloc_traits::pointer pointer; 352349cc55cSDimitry Andric typedef typename __alloc_traits::const_pointer const_pointer; 3530b57cec5SDimitry Andric typedef __wrap_iter<pointer> iterator; 3540b57cec5SDimitry Andric typedef __wrap_iter<const_pointer> const_iterator; 3550b57cec5SDimitry Andric typedef _VSTD::reverse_iterator<iterator> reverse_iterator; 3560b57cec5SDimitry Andric typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; 3570b57cec5SDimitry Andric 3580b57cec5SDimitry Andric static_assert((is_same<typename allocator_type::value_type, value_type>::value), 3590b57cec5SDimitry Andric "Allocator::value_type must be same type as value_type"); 3600b57cec5SDimitry Andric 3610b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3620b57cec5SDimitry Andric vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) 3630b57cec5SDimitry Andric { 36404eeddc0SDimitry Andric _VSTD::__debug_db_insert_c(this); 3650b57cec5SDimitry Andric } 3660b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a) 3670b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14 3680b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value) 3690b57cec5SDimitry Andric#else 3700b57cec5SDimitry Andric _NOEXCEPT 3710b57cec5SDimitry Andric#endif 372d56accc7SDimitry Andric : __end_cap_(nullptr, __a) 3730b57cec5SDimitry Andric { 37404eeddc0SDimitry Andric _VSTD::__debug_db_insert_c(this); 3750b57cec5SDimitry Andric } 3760b57cec5SDimitry Andric explicit vector(size_type __n); 3770b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 3780b57cec5SDimitry Andric explicit vector(size_type __n, const allocator_type& __a); 3790b57cec5SDimitry Andric#endif 3800b57cec5SDimitry Andric vector(size_type __n, const value_type& __x); 3814824e7fdSDimitry Andric 3824824e7fdSDimitry Andric template <class = __enable_if_t<__is_allocator<_Allocator>::value> > 3834824e7fdSDimitry Andric vector(size_type __n, const value_type& __x, const allocator_type& __a) 384d56accc7SDimitry Andric : __end_cap_(nullptr, __a) 3854824e7fdSDimitry Andric { 38604eeddc0SDimitry Andric _VSTD::__debug_db_insert_c(this); 3874824e7fdSDimitry Andric if (__n > 0) 3884824e7fdSDimitry Andric { 3894824e7fdSDimitry Andric __vallocate(__n); 3904824e7fdSDimitry Andric __construct_at_end(__n, __x); 3914824e7fdSDimitry Andric } 3924824e7fdSDimitry Andric } 3934824e7fdSDimitry Andric 3940b57cec5SDimitry Andric template <class _InputIterator> 3950b57cec5SDimitry Andric vector(_InputIterator __first, 396480093f4SDimitry Andric typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value && 397480093f4SDimitry Andric !__is_cpp17_forward_iterator<_InputIterator>::value && 3980b57cec5SDimitry Andric is_constructible< 3990b57cec5SDimitry Andric value_type, 4000b57cec5SDimitry Andric typename iterator_traits<_InputIterator>::reference>::value, 4010b57cec5SDimitry Andric _InputIterator>::type __last); 4020b57cec5SDimitry Andric template <class _InputIterator> 4030b57cec5SDimitry Andric vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, 404480093f4SDimitry Andric typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value && 405480093f4SDimitry Andric !__is_cpp17_forward_iterator<_InputIterator>::value && 4060b57cec5SDimitry Andric is_constructible< 4070b57cec5SDimitry Andric value_type, 4080b57cec5SDimitry Andric typename iterator_traits<_InputIterator>::reference>::value>::type* = 0); 4090b57cec5SDimitry Andric template <class _ForwardIterator> 4100b57cec5SDimitry Andric vector(_ForwardIterator __first, 411480093f4SDimitry Andric typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value && 4120b57cec5SDimitry Andric is_constructible< 4130b57cec5SDimitry Andric value_type, 4140b57cec5SDimitry Andric typename iterator_traits<_ForwardIterator>::reference>::value, 4150b57cec5SDimitry Andric _ForwardIterator>::type __last); 4160b57cec5SDimitry Andric template <class _ForwardIterator> 4170b57cec5SDimitry Andric vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, 418480093f4SDimitry Andric typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value && 4190b57cec5SDimitry Andric is_constructible< 4200b57cec5SDimitry Andric value_type, 4210b57cec5SDimitry Andric typename iterator_traits<_ForwardIterator>::reference>::value>::type* = 0); 4220b57cec5SDimitry Andric 4230b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4240b57cec5SDimitry Andric ~vector() 4250b57cec5SDimitry Andric { 4260b57cec5SDimitry Andric __annotate_delete(); 427*81ad6265SDimitry Andric std::__debug_db_erase_c(this); 428349cc55cSDimitry Andric 429349cc55cSDimitry Andric if (this->__begin_ != nullptr) 430349cc55cSDimitry Andric { 431349cc55cSDimitry Andric __clear(); 432349cc55cSDimitry Andric __alloc_traits::deallocate(__alloc(), this->__begin_, capacity()); 433349cc55cSDimitry Andric } 4340b57cec5SDimitry Andric } 4350b57cec5SDimitry Andric 4360b57cec5SDimitry Andric vector(const vector& __x); 437*81ad6265SDimitry Andric vector(const vector& __x, const __type_identity_t<allocator_type>& __a); 4380b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4390b57cec5SDimitry Andric vector& operator=(const vector& __x); 4400b57cec5SDimitry Andric 4410b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 4420b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4430b57cec5SDimitry Andric vector(initializer_list<value_type> __il); 4440b57cec5SDimitry Andric 4450b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4460b57cec5SDimitry Andric vector(initializer_list<value_type> __il, const allocator_type& __a); 4470b57cec5SDimitry Andric 4480b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 449*81ad6265SDimitry Andric vector& operator=(initializer_list<value_type> __il) 450*81ad6265SDimitry Andric {assign(__il.begin(), __il.end()); return *this;} 451*81ad6265SDimitry Andric#endif // !_LIBCPP_CXX03_LANG 452*81ad6265SDimitry Andric 453*81ad6265SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4540b57cec5SDimitry Andric vector(vector&& __x) 4550b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 456*81ad6265SDimitry Andric noexcept; 4570b57cec5SDimitry Andric#else 4580b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); 4590b57cec5SDimitry Andric#endif 4600b57cec5SDimitry Andric 4610b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 462*81ad6265SDimitry Andric vector(vector&& __x, const __type_identity_t<allocator_type>& __a); 4630b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4640b57cec5SDimitry Andric vector& operator=(vector&& __x) 4650b57cec5SDimitry Andric _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)); 4660b57cec5SDimitry Andric 4670b57cec5SDimitry Andric template <class _InputIterator> 4680b57cec5SDimitry Andric typename enable_if 4690b57cec5SDimitry Andric < 470480093f4SDimitry Andric __is_cpp17_input_iterator <_InputIterator>::value && 471480093f4SDimitry Andric !__is_cpp17_forward_iterator<_InputIterator>::value && 4720b57cec5SDimitry Andric is_constructible< 4730b57cec5SDimitry Andric value_type, 4740b57cec5SDimitry Andric typename iterator_traits<_InputIterator>::reference>::value, 4750b57cec5SDimitry Andric void 4760b57cec5SDimitry Andric >::type 4770b57cec5SDimitry Andric assign(_InputIterator __first, _InputIterator __last); 4780b57cec5SDimitry Andric template <class _ForwardIterator> 4790b57cec5SDimitry Andric typename enable_if 4800b57cec5SDimitry Andric < 481480093f4SDimitry Andric __is_cpp17_forward_iterator<_ForwardIterator>::value && 4820b57cec5SDimitry Andric is_constructible< 4830b57cec5SDimitry Andric value_type, 4840b57cec5SDimitry Andric typename iterator_traits<_ForwardIterator>::reference>::value, 4850b57cec5SDimitry Andric void 4860b57cec5SDimitry Andric >::type 4870b57cec5SDimitry Andric assign(_ForwardIterator __first, _ForwardIterator __last); 4880b57cec5SDimitry Andric 4890b57cec5SDimitry Andric void assign(size_type __n, const_reference __u); 4900b57cec5SDimitry Andric 4910b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 4920b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4930b57cec5SDimitry Andric void assign(initializer_list<value_type> __il) 4940b57cec5SDimitry Andric {assign(__il.begin(), __il.end());} 4950b57cec5SDimitry Andric#endif 4960b57cec5SDimitry Andric 4970b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4980b57cec5SDimitry Andric allocator_type get_allocator() const _NOEXCEPT 4990b57cec5SDimitry Andric {return this->__alloc();} 5000b57cec5SDimitry Andric 5010b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT; 5020b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT; 5030b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT; 5040b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT; 5050b57cec5SDimitry Andric 5060b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5070b57cec5SDimitry Andric reverse_iterator rbegin() _NOEXCEPT 5080b57cec5SDimitry Andric {return reverse_iterator(end());} 5090b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5100b57cec5SDimitry Andric const_reverse_iterator rbegin() const _NOEXCEPT 5110b57cec5SDimitry Andric {return const_reverse_iterator(end());} 5120b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5130b57cec5SDimitry Andric reverse_iterator rend() _NOEXCEPT 5140b57cec5SDimitry Andric {return reverse_iterator(begin());} 5150b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5160b57cec5SDimitry Andric const_reverse_iterator rend() const _NOEXCEPT 5170b57cec5SDimitry Andric {return const_reverse_iterator(begin());} 5180b57cec5SDimitry Andric 5190b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5200b57cec5SDimitry Andric const_iterator cbegin() const _NOEXCEPT 5210b57cec5SDimitry Andric {return begin();} 5220b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5230b57cec5SDimitry Andric const_iterator cend() const _NOEXCEPT 5240b57cec5SDimitry Andric {return end();} 5250b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5260b57cec5SDimitry Andric const_reverse_iterator crbegin() const _NOEXCEPT 5270b57cec5SDimitry Andric {return rbegin();} 5280b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5290b57cec5SDimitry Andric const_reverse_iterator crend() const _NOEXCEPT 5300b57cec5SDimitry Andric {return rend();} 5310b57cec5SDimitry Andric 5320b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5330b57cec5SDimitry Andric size_type size() const _NOEXCEPT 5340b57cec5SDimitry Andric {return static_cast<size_type>(this->__end_ - this->__begin_);} 5350b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5360b57cec5SDimitry Andric size_type capacity() const _NOEXCEPT 537349cc55cSDimitry Andric {return static_cast<size_type>(__end_cap() - this->__begin_);} 5380b57cec5SDimitry Andric _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 5390b57cec5SDimitry Andric bool empty() const _NOEXCEPT 5400b57cec5SDimitry Andric {return this->__begin_ == this->__end_;} 5410b57cec5SDimitry Andric size_type max_size() const _NOEXCEPT; 5420b57cec5SDimitry Andric void reserve(size_type __n); 5430b57cec5SDimitry Andric void shrink_to_fit() _NOEXCEPT; 5440b57cec5SDimitry Andric 5450b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) _NOEXCEPT; 5460b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const _NOEXCEPT; 5470b57cec5SDimitry Andric reference at(size_type __n); 5480b57cec5SDimitry Andric const_reference at(size_type __n) const; 5490b57cec5SDimitry Andric 5500b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY reference front() _NOEXCEPT 5510b57cec5SDimitry Andric { 552fe6060f1SDimitry Andric _LIBCPP_ASSERT(!empty(), "front() called on an empty vector"); 5530b57cec5SDimitry Andric return *this->__begin_; 5540b57cec5SDimitry Andric } 5550b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY const_reference front() const _NOEXCEPT 5560b57cec5SDimitry Andric { 557fe6060f1SDimitry Andric _LIBCPP_ASSERT(!empty(), "front() called on an empty vector"); 5580b57cec5SDimitry Andric return *this->__begin_; 5590b57cec5SDimitry Andric } 5600b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY reference back() _NOEXCEPT 5610b57cec5SDimitry Andric { 562fe6060f1SDimitry Andric _LIBCPP_ASSERT(!empty(), "back() called on an empty vector"); 5630b57cec5SDimitry Andric return *(this->__end_ - 1); 5640b57cec5SDimitry Andric } 5650b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY const_reference back() const _NOEXCEPT 5660b57cec5SDimitry Andric { 567fe6060f1SDimitry Andric _LIBCPP_ASSERT(!empty(), "back() called on an empty vector"); 5680b57cec5SDimitry Andric return *(this->__end_ - 1); 5690b57cec5SDimitry Andric } 5700b57cec5SDimitry Andric 5710b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5720b57cec5SDimitry Andric value_type* data() _NOEXCEPT 573480093f4SDimitry Andric {return _VSTD::__to_address(this->__begin_);} 5740b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5750b57cec5SDimitry Andric const value_type* data() const _NOEXCEPT 576480093f4SDimitry Andric {return _VSTD::__to_address(this->__begin_);} 5770b57cec5SDimitry Andric 5780b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x); 5790b57cec5SDimitry Andric 5800b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x); 5810b57cec5SDimitry Andric 5820b57cec5SDimitry Andric template <class... _Args> 5830b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5840b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 5850b57cec5SDimitry Andric reference emplace_back(_Args&&... __args); 5860b57cec5SDimitry Andric#else 5870b57cec5SDimitry Andric void emplace_back(_Args&&... __args); 5880b57cec5SDimitry Andric#endif 5890b57cec5SDimitry Andric 5900b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5910b57cec5SDimitry Andric void pop_back(); 5920b57cec5SDimitry Andric 5930b57cec5SDimitry Andric iterator insert(const_iterator __position, const_reference __x); 5940b57cec5SDimitry Andric 5950b57cec5SDimitry Andric iterator insert(const_iterator __position, value_type&& __x); 5960b57cec5SDimitry Andric template <class... _Args> 5970b57cec5SDimitry Andric iterator emplace(const_iterator __position, _Args&&... __args); 5980b57cec5SDimitry Andric 5990b57cec5SDimitry Andric iterator insert(const_iterator __position, size_type __n, const_reference __x); 6000b57cec5SDimitry Andric template <class _InputIterator> 6010b57cec5SDimitry Andric typename enable_if 6020b57cec5SDimitry Andric < 603480093f4SDimitry Andric __is_cpp17_input_iterator <_InputIterator>::value && 604480093f4SDimitry Andric !__is_cpp17_forward_iterator<_InputIterator>::value && 6050b57cec5SDimitry Andric is_constructible< 6060b57cec5SDimitry Andric value_type, 6070b57cec5SDimitry Andric typename iterator_traits<_InputIterator>::reference>::value, 6080b57cec5SDimitry Andric iterator 6090b57cec5SDimitry Andric >::type 6100b57cec5SDimitry Andric insert(const_iterator __position, _InputIterator __first, _InputIterator __last); 6110b57cec5SDimitry Andric template <class _ForwardIterator> 6120b57cec5SDimitry Andric typename enable_if 6130b57cec5SDimitry Andric < 614480093f4SDimitry Andric __is_cpp17_forward_iterator<_ForwardIterator>::value && 6150b57cec5SDimitry Andric is_constructible< 6160b57cec5SDimitry Andric value_type, 6170b57cec5SDimitry Andric typename iterator_traits<_ForwardIterator>::reference>::value, 6180b57cec5SDimitry Andric iterator 6190b57cec5SDimitry Andric >::type 6200b57cec5SDimitry Andric insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last); 6210b57cec5SDimitry Andric 6220b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 6230b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6240b57cec5SDimitry Andric iterator insert(const_iterator __position, initializer_list<value_type> __il) 6250b57cec5SDimitry Andric {return insert(__position, __il.begin(), __il.end());} 6260b57cec5SDimitry Andric#endif 6270b57cec5SDimitry Andric 6280b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position); 6290b57cec5SDimitry Andric iterator erase(const_iterator __first, const_iterator __last); 6300b57cec5SDimitry Andric 6310b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6320b57cec5SDimitry Andric void clear() _NOEXCEPT 6330b57cec5SDimitry Andric { 6340b57cec5SDimitry Andric size_type __old_size = size(); 635349cc55cSDimitry Andric __clear(); 6360b57cec5SDimitry Andric __annotate_shrink(__old_size); 637*81ad6265SDimitry Andric std::__debug_db_invalidate_all(this); 6380b57cec5SDimitry Andric } 6390b57cec5SDimitry Andric 6400b57cec5SDimitry Andric void resize(size_type __sz); 6410b57cec5SDimitry Andric void resize(size_type __sz, const_reference __x); 6420b57cec5SDimitry Andric 6430b57cec5SDimitry Andric void swap(vector&) 6440b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14 6450b57cec5SDimitry Andric _NOEXCEPT; 6460b57cec5SDimitry Andric#else 6470b57cec5SDimitry Andric _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || 6480b57cec5SDimitry Andric __is_nothrow_swappable<allocator_type>::value); 6490b57cec5SDimitry Andric#endif 6500b57cec5SDimitry Andric 6510b57cec5SDimitry Andric bool __invariants() const; 6520b57cec5SDimitry Andric 653*81ad6265SDimitry Andric#ifdef _LIBCPP_ENABLE_DEBUG_MODE 6540b57cec5SDimitry Andric 6550b57cec5SDimitry Andric bool __dereferenceable(const const_iterator* __i) const; 6560b57cec5SDimitry Andric bool __decrementable(const const_iterator* __i) const; 6570b57cec5SDimitry Andric bool __addable(const const_iterator* __i, ptrdiff_t __n) const; 6580b57cec5SDimitry Andric bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const; 6590b57cec5SDimitry Andric 660*81ad6265SDimitry Andric#endif // _LIBCPP_ENABLE_DEBUG_MODE 6610b57cec5SDimitry Andric 6620b57cec5SDimitry Andricprivate: 663d56accc7SDimitry Andric pointer __begin_ = nullptr; 664d56accc7SDimitry Andric pointer __end_ = nullptr; 665d56accc7SDimitry Andric __compressed_pair<pointer, allocator_type> __end_cap_ = 666d56accc7SDimitry Andric __compressed_pair<pointer, allocator_type>(nullptr, __default_init_tag()); 667d56accc7SDimitry Andric 6680b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(pointer __new_last); 669*81ad6265SDimitry Andric 670*81ad6265SDimitry Andric 671*81ad6265SDimitry Andric // Allocate space for __n objects 672*81ad6265SDimitry Andric // throws length_error if __n > max_size() 673*81ad6265SDimitry Andric // throws (probably bad_alloc) if memory run out 674*81ad6265SDimitry Andric // Precondition: __begin_ == __end_ == __end_cap() == 0 675*81ad6265SDimitry Andric // Precondition: __n > 0 676*81ad6265SDimitry Andric // Postcondition: capacity() >= __n 677*81ad6265SDimitry Andric // Postcondition: size() == 0 678*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI void __vallocate(size_type __n) { 679*81ad6265SDimitry Andric if (__n > max_size()) 680*81ad6265SDimitry Andric __throw_length_error(); 681*81ad6265SDimitry Andric auto __allocation = std::__allocate_at_least(__alloc(), __n); 682*81ad6265SDimitry Andric __begin_ = __allocation.ptr; 683*81ad6265SDimitry Andric __end_ = __allocation.ptr; 684*81ad6265SDimitry Andric __end_cap() = __begin_ + __allocation.count; 685*81ad6265SDimitry Andric __annotate_new(0); 686*81ad6265SDimitry Andric } 687*81ad6265SDimitry Andric 6880b57cec5SDimitry Andric void __vdeallocate() _NOEXCEPT; 6890b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const; 6900b57cec5SDimitry Andric void __construct_at_end(size_type __n); 6910b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6920b57cec5SDimitry Andric void __construct_at_end(size_type __n, const_reference __x); 6930b57cec5SDimitry Andric template <class _ForwardIterator> 6940b57cec5SDimitry Andric typename enable_if 6950b57cec5SDimitry Andric < 696480093f4SDimitry Andric __is_cpp17_forward_iterator<_ForwardIterator>::value, 6970b57cec5SDimitry Andric void 6980b57cec5SDimitry Andric >::type 6990b57cec5SDimitry Andric __construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n); 7000b57cec5SDimitry Andric void __append(size_type __n); 7010b57cec5SDimitry Andric void __append(size_type __n, const_reference __x); 7020b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 7030b57cec5SDimitry Andric iterator __make_iter(pointer __p) _NOEXCEPT; 7040b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 7050b57cec5SDimitry Andric const_iterator __make_iter(const_pointer __p) const _NOEXCEPT; 7060b57cec5SDimitry Andric void __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v); 7070b57cec5SDimitry Andric pointer __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p); 7080b57cec5SDimitry Andric void __move_range(pointer __from_s, pointer __from_e, pointer __to); 7090b57cec5SDimitry Andric void __move_assign(vector& __c, true_type) 7100b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); 7110b57cec5SDimitry Andric void __move_assign(vector& __c, false_type) 7120b57cec5SDimitry Andric _NOEXCEPT_(__alloc_traits::is_always_equal::value); 7130b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 7140b57cec5SDimitry Andric void __destruct_at_end(pointer __new_last) _NOEXCEPT 7150b57cec5SDimitry Andric { 7160b57cec5SDimitry Andric __invalidate_iterators_past(__new_last); 7170b57cec5SDimitry Andric size_type __old_size = size(); 718349cc55cSDimitry Andric __base_destruct_at_end(__new_last); 7190b57cec5SDimitry Andric __annotate_shrink(__old_size); 7200b57cec5SDimitry Andric } 7210b57cec5SDimitry Andric 7220b57cec5SDimitry Andric template <class _Up> 7230b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 7240b57cec5SDimitry Andric inline void __push_back_slow_path(_Up&& __x); 7250b57cec5SDimitry Andric 7260b57cec5SDimitry Andric template <class... _Args> 7270b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 7280b57cec5SDimitry Andric inline void __emplace_back_slow_path(_Args&&... __args); 7290b57cec5SDimitry Andric 7300b57cec5SDimitry Andric // The following functions are no-ops outside of AddressSanitizer mode. 7310b57cec5SDimitry Andric // We call annotatations only for the default Allocator because other allocators 7320b57cec5SDimitry Andric // may not meet the AddressSanitizer alignment constraints. 7330b57cec5SDimitry Andric // See the documentation for __sanitizer_annotate_contiguous_container for more details. 7340b57cec5SDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN 7350b57cec5SDimitry Andric void __annotate_contiguous_container(const void *__beg, const void *__end, 7360b57cec5SDimitry Andric const void *__old_mid, 7370b57cec5SDimitry Andric const void *__new_mid) const 7380b57cec5SDimitry Andric { 7390b57cec5SDimitry Andric 7400b57cec5SDimitry Andric if (__beg && is_same<allocator_type, __default_allocator_type>::value) 7410b57cec5SDimitry Andric __sanitizer_annotate_contiguous_container(__beg, __end, __old_mid, __new_mid); 7420b57cec5SDimitry Andric } 7430b57cec5SDimitry Andric#else 7440b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 7450b57cec5SDimitry Andric void __annotate_contiguous_container(const void*, const void*, const void*, 746e40139ffSDimitry Andric const void*) const _NOEXCEPT {} 7470b57cec5SDimitry Andric#endif 7480b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 749e40139ffSDimitry Andric void __annotate_new(size_type __current_size) const _NOEXCEPT { 7500b57cec5SDimitry Andric __annotate_contiguous_container(data(), data() + capacity(), 7510b57cec5SDimitry Andric data() + capacity(), data() + __current_size); 7520b57cec5SDimitry Andric } 7530b57cec5SDimitry Andric 7540b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 755e40139ffSDimitry Andric void __annotate_delete() const _NOEXCEPT { 7560b57cec5SDimitry Andric __annotate_contiguous_container(data(), data() + capacity(), 7570b57cec5SDimitry Andric data() + size(), data() + capacity()); 7580b57cec5SDimitry Andric } 7590b57cec5SDimitry Andric 7600b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 761e40139ffSDimitry Andric void __annotate_increase(size_type __n) const _NOEXCEPT 7620b57cec5SDimitry Andric { 7630b57cec5SDimitry Andric __annotate_contiguous_container(data(), data() + capacity(), 7640b57cec5SDimitry Andric data() + size(), data() + size() + __n); 7650b57cec5SDimitry Andric } 7660b57cec5SDimitry Andric 7670b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 768e40139ffSDimitry Andric void __annotate_shrink(size_type __old_size) const _NOEXCEPT 7690b57cec5SDimitry Andric { 7700b57cec5SDimitry Andric __annotate_contiguous_container(data(), data() + capacity(), 7710b57cec5SDimitry Andric data() + __old_size, data() + size()); 7720b57cec5SDimitry Andric } 7730b57cec5SDimitry Andric 774e40139ffSDimitry Andric struct _ConstructTransaction { 775e40139ffSDimitry Andric explicit _ConstructTransaction(vector &__v, size_type __n) 776e40139ffSDimitry Andric : __v_(__v), __pos_(__v.__end_), __new_end_(__v.__end_ + __n) { 777e40139ffSDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN 778e40139ffSDimitry Andric __v_.__annotate_increase(__n); 779e40139ffSDimitry Andric#endif 780e40139ffSDimitry Andric } 781e40139ffSDimitry Andric ~_ConstructTransaction() { 782e40139ffSDimitry Andric __v_.__end_ = __pos_; 783e40139ffSDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN 784e40139ffSDimitry Andric if (__pos_ != __new_end_) { 785e40139ffSDimitry Andric __v_.__annotate_shrink(__new_end_ - __v_.__begin_); 786e40139ffSDimitry Andric } 787e40139ffSDimitry Andric#endif 788e40139ffSDimitry Andric } 789e40139ffSDimitry Andric 790e40139ffSDimitry Andric vector &__v_; 791e40139ffSDimitry Andric pointer __pos_; 792e40139ffSDimitry Andric const_pointer const __new_end_; 793e40139ffSDimitry Andric 794e40139ffSDimitry Andric private: 795e40139ffSDimitry Andric _ConstructTransaction(_ConstructTransaction const&) = delete; 796e40139ffSDimitry Andric _ConstructTransaction& operator=(_ConstructTransaction const&) = delete; 797e40139ffSDimitry Andric }; 798e40139ffSDimitry Andric 799e40139ffSDimitry Andric template <class ..._Args> 800e40139ffSDimitry Andric _LIBCPP_INLINE_VISIBILITY 801e40139ffSDimitry Andric void __construct_one_at_end(_Args&& ...__args) { 802e40139ffSDimitry Andric _ConstructTransaction __tx(*this, 1); 803480093f4SDimitry Andric __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__tx.__pos_), 804e40139ffSDimitry Andric _VSTD::forward<_Args>(__args)...); 805e40139ffSDimitry Andric ++__tx.__pos_; 806e40139ffSDimitry Andric } 807349cc55cSDimitry Andric 808349cc55cSDimitry Andric _LIBCPP_INLINE_VISIBILITY 809349cc55cSDimitry Andric allocator_type& __alloc() _NOEXCEPT 810349cc55cSDimitry Andric {return this->__end_cap_.second();} 811349cc55cSDimitry Andric _LIBCPP_INLINE_VISIBILITY 812349cc55cSDimitry Andric const allocator_type& __alloc() const _NOEXCEPT 813349cc55cSDimitry Andric {return this->__end_cap_.second();} 814349cc55cSDimitry Andric _LIBCPP_INLINE_VISIBILITY 815349cc55cSDimitry Andric pointer& __end_cap() _NOEXCEPT 816349cc55cSDimitry Andric {return this->__end_cap_.first();} 817349cc55cSDimitry Andric _LIBCPP_INLINE_VISIBILITY 818349cc55cSDimitry Andric const pointer& __end_cap() const _NOEXCEPT 819349cc55cSDimitry Andric {return this->__end_cap_.first();} 820349cc55cSDimitry Andric 821349cc55cSDimitry Andric _LIBCPP_INLINE_VISIBILITY 822349cc55cSDimitry Andric void __clear() _NOEXCEPT {__base_destruct_at_end(this->__begin_);} 823349cc55cSDimitry Andric 824349cc55cSDimitry Andric _LIBCPP_INLINE_VISIBILITY 825349cc55cSDimitry Andric void __base_destruct_at_end(pointer __new_last) _NOEXCEPT { 826349cc55cSDimitry Andric pointer __soon_to_be_end = this->__end_; 827349cc55cSDimitry Andric while (__new_last != __soon_to_be_end) 828349cc55cSDimitry Andric __alloc_traits::destroy(__alloc(), _VSTD::__to_address(--__soon_to_be_end)); 829349cc55cSDimitry Andric this->__end_ = __new_last; 830349cc55cSDimitry Andric } 831349cc55cSDimitry Andric 832349cc55cSDimitry Andric _LIBCPP_INLINE_VISIBILITY 833349cc55cSDimitry Andric void __copy_assign_alloc(const vector& __c) 834349cc55cSDimitry Andric {__copy_assign_alloc(__c, integral_constant<bool, 835349cc55cSDimitry Andric __alloc_traits::propagate_on_container_copy_assignment::value>());} 836349cc55cSDimitry Andric 837349cc55cSDimitry Andric _LIBCPP_INLINE_VISIBILITY 838349cc55cSDimitry Andric void __move_assign_alloc(vector& __c) 839349cc55cSDimitry Andric _NOEXCEPT_( 840349cc55cSDimitry Andric !__alloc_traits::propagate_on_container_move_assignment::value || 841349cc55cSDimitry Andric is_nothrow_move_assignable<allocator_type>::value) 842349cc55cSDimitry Andric {__move_assign_alloc(__c, integral_constant<bool, 843349cc55cSDimitry Andric __alloc_traits::propagate_on_container_move_assignment::value>());} 844349cc55cSDimitry Andric 845349cc55cSDimitry Andric _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI 846349cc55cSDimitry Andric void __throw_length_error() const { 847d56accc7SDimitry Andric _VSTD::__throw_length_error("vector"); 848349cc55cSDimitry Andric } 849349cc55cSDimitry Andric 850349cc55cSDimitry Andric _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI 851349cc55cSDimitry Andric void __throw_out_of_range() const { 852d56accc7SDimitry Andric _VSTD::__throw_out_of_range("vector"); 853349cc55cSDimitry Andric } 854349cc55cSDimitry Andric 855349cc55cSDimitry Andric _LIBCPP_INLINE_VISIBILITY 856349cc55cSDimitry Andric void __copy_assign_alloc(const vector& __c, true_type) 857349cc55cSDimitry Andric { 858349cc55cSDimitry Andric if (__alloc() != __c.__alloc()) 859349cc55cSDimitry Andric { 860349cc55cSDimitry Andric __clear(); 861349cc55cSDimitry Andric __alloc_traits::deallocate(__alloc(), this->__begin_, capacity()); 862349cc55cSDimitry Andric this->__begin_ = this->__end_ = __end_cap() = nullptr; 863349cc55cSDimitry Andric } 864349cc55cSDimitry Andric __alloc() = __c.__alloc(); 865349cc55cSDimitry Andric } 866349cc55cSDimitry Andric 867349cc55cSDimitry Andric _LIBCPP_INLINE_VISIBILITY 868349cc55cSDimitry Andric void __copy_assign_alloc(const vector&, false_type) 869349cc55cSDimitry Andric {} 870349cc55cSDimitry Andric 871349cc55cSDimitry Andric _LIBCPP_INLINE_VISIBILITY 872349cc55cSDimitry Andric void __move_assign_alloc(vector& __c, true_type) 873349cc55cSDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) 874349cc55cSDimitry Andric { 875349cc55cSDimitry Andric __alloc() = _VSTD::move(__c.__alloc()); 876349cc55cSDimitry Andric } 877349cc55cSDimitry Andric 878349cc55cSDimitry Andric _LIBCPP_INLINE_VISIBILITY 879349cc55cSDimitry Andric void __move_assign_alloc(vector&, false_type) 880349cc55cSDimitry Andric _NOEXCEPT 881349cc55cSDimitry Andric {} 8820b57cec5SDimitry Andric}; 8830b57cec5SDimitry Andric 884349cc55cSDimitry Andric#if _LIBCPP_STD_VER >= 17 8850b57cec5SDimitry Andrictemplate<class _InputIterator, 886fe6060f1SDimitry Andric class _Alloc = allocator<__iter_value_type<_InputIterator>>, 887349cc55cSDimitry Andric class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>, 888349cc55cSDimitry Andric class = enable_if_t<__is_allocator<_Alloc>::value> 8890b57cec5SDimitry Andric > 8900b57cec5SDimitry Andricvector(_InputIterator, _InputIterator) 891fe6060f1SDimitry Andric -> vector<__iter_value_type<_InputIterator>, _Alloc>; 8920b57cec5SDimitry Andric 8930b57cec5SDimitry Andrictemplate<class _InputIterator, 8940b57cec5SDimitry Andric class _Alloc, 895349cc55cSDimitry Andric class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>, 896349cc55cSDimitry Andric class = enable_if_t<__is_allocator<_Alloc>::value> 8970b57cec5SDimitry Andric > 8980b57cec5SDimitry Andricvector(_InputIterator, _InputIterator, _Alloc) 899fe6060f1SDimitry Andric -> vector<__iter_value_type<_InputIterator>, _Alloc>; 9000b57cec5SDimitry Andric#endif 9010b57cec5SDimitry Andric 9020b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 9030b57cec5SDimitry Andricvoid 9040b57cec5SDimitry Andricvector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v) 9050b57cec5SDimitry Andric{ 906e40139ffSDimitry Andric 9070b57cec5SDimitry Andric __annotate_delete(); 908e8d8bef9SDimitry Andric _VSTD::__construct_backward_with_exception_guarantees(this->__alloc(), this->__begin_, this->__end_, __v.__begin_); 9090b57cec5SDimitry Andric _VSTD::swap(this->__begin_, __v.__begin_); 9100b57cec5SDimitry Andric _VSTD::swap(this->__end_, __v.__end_); 9110b57cec5SDimitry Andric _VSTD::swap(this->__end_cap(), __v.__end_cap()); 9120b57cec5SDimitry Andric __v.__first_ = __v.__begin_; 9130b57cec5SDimitry Andric __annotate_new(size()); 914*81ad6265SDimitry Andric std::__debug_db_invalidate_all(this); 9150b57cec5SDimitry Andric} 9160b57cec5SDimitry Andric 9170b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 9180b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::pointer 9190b57cec5SDimitry Andricvector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p) 9200b57cec5SDimitry Andric{ 9210b57cec5SDimitry Andric __annotate_delete(); 9220b57cec5SDimitry Andric pointer __r = __v.__begin_; 923e8d8bef9SDimitry Andric _VSTD::__construct_backward_with_exception_guarantees(this->__alloc(), this->__begin_, __p, __v.__begin_); 924e8d8bef9SDimitry Andric _VSTD::__construct_forward_with_exception_guarantees(this->__alloc(), __p, this->__end_, __v.__end_); 9250b57cec5SDimitry Andric _VSTD::swap(this->__begin_, __v.__begin_); 9260b57cec5SDimitry Andric _VSTD::swap(this->__end_, __v.__end_); 9270b57cec5SDimitry Andric _VSTD::swap(this->__end_cap(), __v.__end_cap()); 9280b57cec5SDimitry Andric __v.__first_ = __v.__begin_; 9290b57cec5SDimitry Andric __annotate_new(size()); 930*81ad6265SDimitry Andric std::__debug_db_invalidate_all(this); 9310b57cec5SDimitry Andric return __r; 9320b57cec5SDimitry Andric} 9330b57cec5SDimitry Andric 9340b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 9350b57cec5SDimitry Andricvoid 9360b57cec5SDimitry Andricvector<_Tp, _Allocator>::__vdeallocate() _NOEXCEPT 9370b57cec5SDimitry Andric{ 9380b57cec5SDimitry Andric if (this->__begin_ != nullptr) 9390b57cec5SDimitry Andric { 9400b57cec5SDimitry Andric clear(); 9410b57cec5SDimitry Andric __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity()); 9420b57cec5SDimitry Andric this->__begin_ = this->__end_ = this->__end_cap() = nullptr; 9430b57cec5SDimitry Andric } 9440b57cec5SDimitry Andric} 9450b57cec5SDimitry Andric 9460b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 9470b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::size_type 9480b57cec5SDimitry Andricvector<_Tp, _Allocator>::max_size() const _NOEXCEPT 9490b57cec5SDimitry Andric{ 9500b57cec5SDimitry Andric return _VSTD::min<size_type>(__alloc_traits::max_size(this->__alloc()), 9510b57cec5SDimitry Andric numeric_limits<difference_type>::max()); 9520b57cec5SDimitry Andric} 9530b57cec5SDimitry Andric 9540b57cec5SDimitry Andric// Precondition: __new_size > capacity() 9550b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 9560b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 9570b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::size_type 9580b57cec5SDimitry Andricvector<_Tp, _Allocator>::__recommend(size_type __new_size) const 9590b57cec5SDimitry Andric{ 9600b57cec5SDimitry Andric const size_type __ms = max_size(); 9610b57cec5SDimitry Andric if (__new_size > __ms) 9620b57cec5SDimitry Andric this->__throw_length_error(); 9630b57cec5SDimitry Andric const size_type __cap = capacity(); 9640b57cec5SDimitry Andric if (__cap >= __ms / 2) 9650b57cec5SDimitry Andric return __ms; 9660b57cec5SDimitry Andric return _VSTD::max<size_type>(2 * __cap, __new_size); 9670b57cec5SDimitry Andric} 9680b57cec5SDimitry Andric 9690b57cec5SDimitry Andric// Default constructs __n objects starting at __end_ 9700b57cec5SDimitry Andric// throws if construction throws 9710b57cec5SDimitry Andric// Precondition: __n > 0 9720b57cec5SDimitry Andric// Precondition: size() + __n <= capacity() 9730b57cec5SDimitry Andric// Postcondition: size() == size() + __n 9740b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 9750b57cec5SDimitry Andricvoid 9760b57cec5SDimitry Andricvector<_Tp, _Allocator>::__construct_at_end(size_type __n) 9770b57cec5SDimitry Andric{ 978e40139ffSDimitry Andric _ConstructTransaction __tx(*this, __n); 9795ffd83dbSDimitry Andric const_pointer __new_end = __tx.__new_end_; 980349cc55cSDimitry Andric for (pointer __pos = __tx.__pos_; __pos != __new_end; __tx.__pos_ = ++__pos) { 9815ffd83dbSDimitry Andric __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__pos)); 982e40139ffSDimitry Andric } 9830b57cec5SDimitry Andric} 9840b57cec5SDimitry Andric 9850b57cec5SDimitry Andric// Copy constructs __n objects starting at __end_ from __x 9860b57cec5SDimitry Andric// throws if construction throws 9870b57cec5SDimitry Andric// Precondition: __n > 0 9880b57cec5SDimitry Andric// Precondition: size() + __n <= capacity() 9890b57cec5SDimitry Andric// Postcondition: size() == old size() + __n 9900b57cec5SDimitry Andric// Postcondition: [i] == __x for all i in [size() - __n, __n) 9910b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 9920b57cec5SDimitry Andricinline 9930b57cec5SDimitry Andricvoid 9940b57cec5SDimitry Andricvector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x) 9950b57cec5SDimitry Andric{ 996e40139ffSDimitry Andric _ConstructTransaction __tx(*this, __n); 9975ffd83dbSDimitry Andric const_pointer __new_end = __tx.__new_end_; 998349cc55cSDimitry Andric for (pointer __pos = __tx.__pos_; __pos != __new_end; __tx.__pos_ = ++__pos) { 9995ffd83dbSDimitry Andric __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__pos), __x); 1000e40139ffSDimitry Andric } 10010b57cec5SDimitry Andric} 10020b57cec5SDimitry Andric 10030b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 10040b57cec5SDimitry Andrictemplate <class _ForwardIterator> 10050b57cec5SDimitry Andrictypename enable_if 10060b57cec5SDimitry Andric< 1007480093f4SDimitry Andric __is_cpp17_forward_iterator<_ForwardIterator>::value, 10080b57cec5SDimitry Andric void 10090b57cec5SDimitry Andric>::type 10100b57cec5SDimitry Andricvector<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n) 10110b57cec5SDimitry Andric{ 1012e40139ffSDimitry Andric _ConstructTransaction __tx(*this, __n); 1013e8d8bef9SDimitry Andric _VSTD::__construct_range_forward(this->__alloc(), __first, __last, __tx.__pos_); 10140b57cec5SDimitry Andric} 10150b57cec5SDimitry Andric 10160b57cec5SDimitry Andric// Default constructs __n objects starting at __end_ 10170b57cec5SDimitry Andric// throws if construction throws 10180b57cec5SDimitry Andric// Postcondition: size() == size() + __n 10190b57cec5SDimitry Andric// Exception safety: strong. 10200b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 10210b57cec5SDimitry Andricvoid 10220b57cec5SDimitry Andricvector<_Tp, _Allocator>::__append(size_type __n) 10230b57cec5SDimitry Andric{ 10240b57cec5SDimitry Andric if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n) 10250b57cec5SDimitry Andric this->__construct_at_end(__n); 10260b57cec5SDimitry Andric else 10270b57cec5SDimitry Andric { 10280b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 10290b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a); 10300b57cec5SDimitry Andric __v.__construct_at_end(__n); 10310b57cec5SDimitry Andric __swap_out_circular_buffer(__v); 10320b57cec5SDimitry Andric } 10330b57cec5SDimitry Andric} 10340b57cec5SDimitry Andric 10350b57cec5SDimitry Andric// Default constructs __n objects starting at __end_ 10360b57cec5SDimitry Andric// throws if construction throws 10370b57cec5SDimitry Andric// Postcondition: size() == size() + __n 10380b57cec5SDimitry Andric// Exception safety: strong. 10390b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 10400b57cec5SDimitry Andricvoid 10410b57cec5SDimitry Andricvector<_Tp, _Allocator>::__append(size_type __n, const_reference __x) 10420b57cec5SDimitry Andric{ 10430b57cec5SDimitry Andric if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n) 10440b57cec5SDimitry Andric this->__construct_at_end(__n, __x); 10450b57cec5SDimitry Andric else 10460b57cec5SDimitry Andric { 10470b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 10480b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a); 10490b57cec5SDimitry Andric __v.__construct_at_end(__n, __x); 10500b57cec5SDimitry Andric __swap_out_circular_buffer(__v); 10510b57cec5SDimitry Andric } 10520b57cec5SDimitry Andric} 10530b57cec5SDimitry Andric 10540b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 10550b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(size_type __n) 10560b57cec5SDimitry Andric{ 105704eeddc0SDimitry Andric _VSTD::__debug_db_insert_c(this); 10580b57cec5SDimitry Andric if (__n > 0) 10590b57cec5SDimitry Andric { 10600b57cec5SDimitry Andric __vallocate(__n); 10610b57cec5SDimitry Andric __construct_at_end(__n); 10620b57cec5SDimitry Andric } 10630b57cec5SDimitry Andric} 10640b57cec5SDimitry Andric 10650b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 10660b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 10670b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a) 1068d56accc7SDimitry Andric : __end_cap_(nullptr, __a) 10690b57cec5SDimitry Andric{ 107004eeddc0SDimitry Andric _VSTD::__debug_db_insert_c(this); 10710b57cec5SDimitry Andric if (__n > 0) 10720b57cec5SDimitry Andric { 10730b57cec5SDimitry Andric __vallocate(__n); 10740b57cec5SDimitry Andric __construct_at_end(__n); 10750b57cec5SDimitry Andric } 10760b57cec5SDimitry Andric} 10770b57cec5SDimitry Andric#endif 10780b57cec5SDimitry Andric 10790b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 10800b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(size_type __n, const value_type& __x) 10810b57cec5SDimitry Andric{ 108204eeddc0SDimitry Andric _VSTD::__debug_db_insert_c(this); 10830b57cec5SDimitry Andric if (__n > 0) 10840b57cec5SDimitry Andric { 10850b57cec5SDimitry Andric __vallocate(__n); 10860b57cec5SDimitry Andric __construct_at_end(__n, __x); 10870b57cec5SDimitry Andric } 10880b57cec5SDimitry Andric} 10890b57cec5SDimitry Andric 10900b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 10910b57cec5SDimitry Andrictemplate <class _InputIterator> 10920b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(_InputIterator __first, 1093480093f4SDimitry Andric typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value && 1094480093f4SDimitry Andric !__is_cpp17_forward_iterator<_InputIterator>::value && 10950b57cec5SDimitry Andric is_constructible< 10960b57cec5SDimitry Andric value_type, 10970b57cec5SDimitry Andric typename iterator_traits<_InputIterator>::reference>::value, 10980b57cec5SDimitry Andric _InputIterator>::type __last) 10990b57cec5SDimitry Andric{ 110004eeddc0SDimitry Andric _VSTD::__debug_db_insert_c(this); 11010b57cec5SDimitry Andric for (; __first != __last; ++__first) 1102*81ad6265SDimitry Andric emplace_back(*__first); 11030b57cec5SDimitry Andric} 11040b57cec5SDimitry Andric 11050b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 11060b57cec5SDimitry Andrictemplate <class _InputIterator> 11070b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, 1108480093f4SDimitry Andric typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value && 1109480093f4SDimitry Andric !__is_cpp17_forward_iterator<_InputIterator>::value && 11100b57cec5SDimitry Andric is_constructible< 11110b57cec5SDimitry Andric value_type, 11120b57cec5SDimitry Andric typename iterator_traits<_InputIterator>::reference>::value>::type*) 1113d56accc7SDimitry Andric : __end_cap_(nullptr, __a) 11140b57cec5SDimitry Andric{ 111504eeddc0SDimitry Andric _VSTD::__debug_db_insert_c(this); 11160b57cec5SDimitry Andric for (; __first != __last; ++__first) 1117*81ad6265SDimitry Andric emplace_back(*__first); 11180b57cec5SDimitry Andric} 11190b57cec5SDimitry Andric 11200b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 11210b57cec5SDimitry Andrictemplate <class _ForwardIterator> 11220b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(_ForwardIterator __first, 1123480093f4SDimitry Andric typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value && 11240b57cec5SDimitry Andric is_constructible< 11250b57cec5SDimitry Andric value_type, 11260b57cec5SDimitry Andric typename iterator_traits<_ForwardIterator>::reference>::value, 11270b57cec5SDimitry Andric _ForwardIterator>::type __last) 11280b57cec5SDimitry Andric{ 112904eeddc0SDimitry Andric _VSTD::__debug_db_insert_c(this); 11300b57cec5SDimitry Andric size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); 11310b57cec5SDimitry Andric if (__n > 0) 11320b57cec5SDimitry Andric { 11330b57cec5SDimitry Andric __vallocate(__n); 11340b57cec5SDimitry Andric __construct_at_end(__first, __last, __n); 11350b57cec5SDimitry Andric } 11360b57cec5SDimitry Andric} 11370b57cec5SDimitry Andric 11380b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 11390b57cec5SDimitry Andrictemplate <class _ForwardIterator> 11400b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, 1141480093f4SDimitry Andric typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value && 11420b57cec5SDimitry Andric is_constructible< 11430b57cec5SDimitry Andric value_type, 11440b57cec5SDimitry Andric typename iterator_traits<_ForwardIterator>::reference>::value>::type*) 1145d56accc7SDimitry Andric : __end_cap_(nullptr, __a) 11460b57cec5SDimitry Andric{ 114704eeddc0SDimitry Andric _VSTD::__debug_db_insert_c(this); 11480b57cec5SDimitry Andric size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); 11490b57cec5SDimitry Andric if (__n > 0) 11500b57cec5SDimitry Andric { 11510b57cec5SDimitry Andric __vallocate(__n); 11520b57cec5SDimitry Andric __construct_at_end(__first, __last, __n); 11530b57cec5SDimitry Andric } 11540b57cec5SDimitry Andric} 11550b57cec5SDimitry Andric 11560b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 11570b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(const vector& __x) 1158d56accc7SDimitry Andric : __end_cap_(nullptr, __alloc_traits::select_on_container_copy_construction(__x.__alloc())) 11590b57cec5SDimitry Andric{ 116004eeddc0SDimitry Andric _VSTD::__debug_db_insert_c(this); 11610b57cec5SDimitry Andric size_type __n = __x.size(); 11620b57cec5SDimitry Andric if (__n > 0) 11630b57cec5SDimitry Andric { 11640b57cec5SDimitry Andric __vallocate(__n); 11650b57cec5SDimitry Andric __construct_at_end(__x.__begin_, __x.__end_, __n); 11660b57cec5SDimitry Andric } 11670b57cec5SDimitry Andric} 11680b57cec5SDimitry Andric 11690b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1170*81ad6265SDimitry Andricvector<_Tp, _Allocator>::vector(const vector& __x, const __type_identity_t<allocator_type>& __a) 1171d56accc7SDimitry Andric : __end_cap_(nullptr, __a) 11720b57cec5SDimitry Andric{ 117304eeddc0SDimitry Andric _VSTD::__debug_db_insert_c(this); 11740b57cec5SDimitry Andric size_type __n = __x.size(); 11750b57cec5SDimitry Andric if (__n > 0) 11760b57cec5SDimitry Andric { 11770b57cec5SDimitry Andric __vallocate(__n); 11780b57cec5SDimitry Andric __construct_at_end(__x.__begin_, __x.__end_, __n); 11790b57cec5SDimitry Andric } 11800b57cec5SDimitry Andric} 11810b57cec5SDimitry Andric 11820b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 11830b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 11840b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(vector&& __x) 11850b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 1186*81ad6265SDimitry Andric noexcept 11870b57cec5SDimitry Andric#else 11880b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) 11890b57cec5SDimitry Andric#endif 1190d56accc7SDimitry Andric : __end_cap_(nullptr, _VSTD::move(__x.__alloc())) 11910b57cec5SDimitry Andric{ 119204eeddc0SDimitry Andric _VSTD::__debug_db_insert_c(this); 1193*81ad6265SDimitry Andric std::__debug_db_swap(this, std::addressof(__x)); 11940b57cec5SDimitry Andric this->__begin_ = __x.__begin_; 11950b57cec5SDimitry Andric this->__end_ = __x.__end_; 11960b57cec5SDimitry Andric this->__end_cap() = __x.__end_cap(); 11970b57cec5SDimitry Andric __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr; 11980b57cec5SDimitry Andric} 11990b57cec5SDimitry Andric 12000b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 12010b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 1202*81ad6265SDimitry Andricvector<_Tp, _Allocator>::vector(vector&& __x, const __type_identity_t<allocator_type>& __a) 1203d56accc7SDimitry Andric : __end_cap_(nullptr, __a) 12040b57cec5SDimitry Andric{ 120504eeddc0SDimitry Andric _VSTD::__debug_db_insert_c(this); 12060b57cec5SDimitry Andric if (__a == __x.__alloc()) 12070b57cec5SDimitry Andric { 12080b57cec5SDimitry Andric this->__begin_ = __x.__begin_; 12090b57cec5SDimitry Andric this->__end_ = __x.__end_; 12100b57cec5SDimitry Andric this->__end_cap() = __x.__end_cap(); 12110b57cec5SDimitry Andric __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr; 1212*81ad6265SDimitry Andric std::__debug_db_swap(this, std::addressof(__x)); 12130b57cec5SDimitry Andric } 12140b57cec5SDimitry Andric else 12150b57cec5SDimitry Andric { 12160b57cec5SDimitry Andric typedef move_iterator<iterator> _Ip; 12170b57cec5SDimitry Andric assign(_Ip(__x.begin()), _Ip(__x.end())); 12180b57cec5SDimitry Andric } 12190b57cec5SDimitry Andric} 12200b57cec5SDimitry Andric 1221*81ad6265SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 1222*81ad6265SDimitry Andric 12230b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 12240b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 12250b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(initializer_list<value_type> __il) 12260b57cec5SDimitry Andric{ 122704eeddc0SDimitry Andric _VSTD::__debug_db_insert_c(this); 12280b57cec5SDimitry Andric if (__il.size() > 0) 12290b57cec5SDimitry Andric { 12300b57cec5SDimitry Andric __vallocate(__il.size()); 12310b57cec5SDimitry Andric __construct_at_end(__il.begin(), __il.end(), __il.size()); 12320b57cec5SDimitry Andric } 12330b57cec5SDimitry Andric} 12340b57cec5SDimitry Andric 12350b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 12360b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 12370b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a) 1238d56accc7SDimitry Andric : __end_cap_(nullptr, __a) 12390b57cec5SDimitry Andric{ 124004eeddc0SDimitry Andric _VSTD::__debug_db_insert_c(this); 12410b57cec5SDimitry Andric if (__il.size() > 0) 12420b57cec5SDimitry Andric { 12430b57cec5SDimitry Andric __vallocate(__il.size()); 12440b57cec5SDimitry Andric __construct_at_end(__il.begin(), __il.end(), __il.size()); 12450b57cec5SDimitry Andric } 12460b57cec5SDimitry Andric} 12470b57cec5SDimitry Andric 1248*81ad6265SDimitry Andric#endif // _LIBCPP_CXX03_LANG 1249*81ad6265SDimitry Andric 12500b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 12510b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 12520b57cec5SDimitry Andricvector<_Tp, _Allocator>& 12530b57cec5SDimitry Andricvector<_Tp, _Allocator>::operator=(vector&& __x) 12540b57cec5SDimitry Andric _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) 12550b57cec5SDimitry Andric{ 12560b57cec5SDimitry Andric __move_assign(__x, integral_constant<bool, 12570b57cec5SDimitry Andric __alloc_traits::propagate_on_container_move_assignment::value>()); 12580b57cec5SDimitry Andric return *this; 12590b57cec5SDimitry Andric} 12600b57cec5SDimitry Andric 12610b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 12620b57cec5SDimitry Andricvoid 12630b57cec5SDimitry Andricvector<_Tp, _Allocator>::__move_assign(vector& __c, false_type) 12640b57cec5SDimitry Andric _NOEXCEPT_(__alloc_traits::is_always_equal::value) 12650b57cec5SDimitry Andric{ 1266349cc55cSDimitry Andric if (__alloc() != __c.__alloc()) 12670b57cec5SDimitry Andric { 12680b57cec5SDimitry Andric typedef move_iterator<iterator> _Ip; 12690b57cec5SDimitry Andric assign(_Ip(__c.begin()), _Ip(__c.end())); 12700b57cec5SDimitry Andric } 12710b57cec5SDimitry Andric else 12720b57cec5SDimitry Andric __move_assign(__c, true_type()); 12730b57cec5SDimitry Andric} 12740b57cec5SDimitry Andric 12750b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 12760b57cec5SDimitry Andricvoid 12770b57cec5SDimitry Andricvector<_Tp, _Allocator>::__move_assign(vector& __c, true_type) 12780b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) 12790b57cec5SDimitry Andric{ 12800b57cec5SDimitry Andric __vdeallocate(); 1281349cc55cSDimitry Andric __move_assign_alloc(__c); // this can throw 12820b57cec5SDimitry Andric this->__begin_ = __c.__begin_; 12830b57cec5SDimitry Andric this->__end_ = __c.__end_; 12840b57cec5SDimitry Andric this->__end_cap() = __c.__end_cap(); 12850b57cec5SDimitry Andric __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr; 1286*81ad6265SDimitry Andric std::__debug_db_swap(this, std::addressof(__c)); 12870b57cec5SDimitry Andric} 12880b57cec5SDimitry Andric 12890b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 12900b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 12910b57cec5SDimitry Andricvector<_Tp, _Allocator>& 12920b57cec5SDimitry Andricvector<_Tp, _Allocator>::operator=(const vector& __x) 12930b57cec5SDimitry Andric{ 1294349cc55cSDimitry Andric if (this != _VSTD::addressof(__x)) 12950b57cec5SDimitry Andric { 1296349cc55cSDimitry Andric __copy_assign_alloc(__x); 12970b57cec5SDimitry Andric assign(__x.__begin_, __x.__end_); 12980b57cec5SDimitry Andric } 12990b57cec5SDimitry Andric return *this; 13000b57cec5SDimitry Andric} 13010b57cec5SDimitry Andric 13020b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 13030b57cec5SDimitry Andrictemplate <class _InputIterator> 13040b57cec5SDimitry Andrictypename enable_if 13050b57cec5SDimitry Andric< 1306480093f4SDimitry Andric __is_cpp17_input_iterator <_InputIterator>::value && 1307480093f4SDimitry Andric !__is_cpp17_forward_iterator<_InputIterator>::value && 13080b57cec5SDimitry Andric is_constructible< 13090b57cec5SDimitry Andric _Tp, 13100b57cec5SDimitry Andric typename iterator_traits<_InputIterator>::reference>::value, 13110b57cec5SDimitry Andric void 13120b57cec5SDimitry Andric>::type 13130b57cec5SDimitry Andricvector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last) 13140b57cec5SDimitry Andric{ 13150b57cec5SDimitry Andric clear(); 13160b57cec5SDimitry Andric for (; __first != __last; ++__first) 1317*81ad6265SDimitry Andric emplace_back(*__first); 13180b57cec5SDimitry Andric} 13190b57cec5SDimitry Andric 13200b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 13210b57cec5SDimitry Andrictemplate <class _ForwardIterator> 13220b57cec5SDimitry Andrictypename enable_if 13230b57cec5SDimitry Andric< 1324480093f4SDimitry Andric __is_cpp17_forward_iterator<_ForwardIterator>::value && 13250b57cec5SDimitry Andric is_constructible< 13260b57cec5SDimitry Andric _Tp, 13270b57cec5SDimitry Andric typename iterator_traits<_ForwardIterator>::reference>::value, 13280b57cec5SDimitry Andric void 13290b57cec5SDimitry Andric>::type 13300b57cec5SDimitry Andricvector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) 13310b57cec5SDimitry Andric{ 13320b57cec5SDimitry Andric size_type __new_size = static_cast<size_type>(_VSTD::distance(__first, __last)); 13330b57cec5SDimitry Andric if (__new_size <= capacity()) 13340b57cec5SDimitry Andric { 13350b57cec5SDimitry Andric _ForwardIterator __mid = __last; 13360b57cec5SDimitry Andric bool __growing = false; 13370b57cec5SDimitry Andric if (__new_size > size()) 13380b57cec5SDimitry Andric { 13390b57cec5SDimitry Andric __growing = true; 13400b57cec5SDimitry Andric __mid = __first; 13410b57cec5SDimitry Andric _VSTD::advance(__mid, size()); 13420b57cec5SDimitry Andric } 13430b57cec5SDimitry Andric pointer __m = _VSTD::copy(__first, __mid, this->__begin_); 13440b57cec5SDimitry Andric if (__growing) 13450b57cec5SDimitry Andric __construct_at_end(__mid, __last, __new_size - size()); 13460b57cec5SDimitry Andric else 13470b57cec5SDimitry Andric this->__destruct_at_end(__m); 13480b57cec5SDimitry Andric } 13490b57cec5SDimitry Andric else 13500b57cec5SDimitry Andric { 13510b57cec5SDimitry Andric __vdeallocate(); 13520b57cec5SDimitry Andric __vallocate(__recommend(__new_size)); 13530b57cec5SDimitry Andric __construct_at_end(__first, __last, __new_size); 13540b57cec5SDimitry Andric } 1355*81ad6265SDimitry Andric std::__debug_db_invalidate_all(this); 13560b57cec5SDimitry Andric} 13570b57cec5SDimitry Andric 13580b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 13590b57cec5SDimitry Andricvoid 13600b57cec5SDimitry Andricvector<_Tp, _Allocator>::assign(size_type __n, const_reference __u) 13610b57cec5SDimitry Andric{ 13620b57cec5SDimitry Andric if (__n <= capacity()) 13630b57cec5SDimitry Andric { 13640b57cec5SDimitry Andric size_type __s = size(); 13650b57cec5SDimitry Andric _VSTD::fill_n(this->__begin_, _VSTD::min(__n, __s), __u); 13660b57cec5SDimitry Andric if (__n > __s) 13670b57cec5SDimitry Andric __construct_at_end(__n - __s, __u); 13680b57cec5SDimitry Andric else 13690b57cec5SDimitry Andric this->__destruct_at_end(this->__begin_ + __n); 13700b57cec5SDimitry Andric } 13710b57cec5SDimitry Andric else 13720b57cec5SDimitry Andric { 13730b57cec5SDimitry Andric __vdeallocate(); 13740b57cec5SDimitry Andric __vallocate(__recommend(static_cast<size_type>(__n))); 13750b57cec5SDimitry Andric __construct_at_end(__n, __u); 13760b57cec5SDimitry Andric } 1377*81ad6265SDimitry Andric std::__debug_db_invalidate_all(this); 13780b57cec5SDimitry Andric} 13790b57cec5SDimitry Andric 13800b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 13810b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 13820b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator 13830b57cec5SDimitry Andricvector<_Tp, _Allocator>::begin() _NOEXCEPT 13840b57cec5SDimitry Andric{ 1385*81ad6265SDimitry Andric return iterator(this, this->__begin_); 13860b57cec5SDimitry Andric} 13870b57cec5SDimitry Andric 13880b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 13890b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 13900b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::const_iterator 13910b57cec5SDimitry Andricvector<_Tp, _Allocator>::begin() const _NOEXCEPT 13920b57cec5SDimitry Andric{ 1393*81ad6265SDimitry Andric return const_iterator(this, this->__begin_); 13940b57cec5SDimitry Andric} 13950b57cec5SDimitry Andric 13960b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 13970b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 13980b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator 13990b57cec5SDimitry Andricvector<_Tp, _Allocator>::end() _NOEXCEPT 14000b57cec5SDimitry Andric{ 1401*81ad6265SDimitry Andric return iterator(this, this->__end_); 14020b57cec5SDimitry Andric} 14030b57cec5SDimitry Andric 14040b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 14050b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 14060b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::const_iterator 14070b57cec5SDimitry Andricvector<_Tp, _Allocator>::end() const _NOEXCEPT 14080b57cec5SDimitry Andric{ 1409*81ad6265SDimitry Andric return const_iterator(this, this->__end_); 14100b57cec5SDimitry Andric} 14110b57cec5SDimitry Andric 14120b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 14130b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 14140b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::reference 14150b57cec5SDimitry Andricvector<_Tp, _Allocator>::operator[](size_type __n) _NOEXCEPT 14160b57cec5SDimitry Andric{ 14170b57cec5SDimitry Andric _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds"); 14180b57cec5SDimitry Andric return this->__begin_[__n]; 14190b57cec5SDimitry Andric} 14200b57cec5SDimitry Andric 14210b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 14220b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 14230b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::const_reference 14240b57cec5SDimitry Andricvector<_Tp, _Allocator>::operator[](size_type __n) const _NOEXCEPT 14250b57cec5SDimitry Andric{ 14260b57cec5SDimitry Andric _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds"); 14270b57cec5SDimitry Andric return this->__begin_[__n]; 14280b57cec5SDimitry Andric} 14290b57cec5SDimitry Andric 14300b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 14310b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::reference 14320b57cec5SDimitry Andricvector<_Tp, _Allocator>::at(size_type __n) 14330b57cec5SDimitry Andric{ 14340b57cec5SDimitry Andric if (__n >= size()) 14350b57cec5SDimitry Andric this->__throw_out_of_range(); 14360b57cec5SDimitry Andric return this->__begin_[__n]; 14370b57cec5SDimitry Andric} 14380b57cec5SDimitry Andric 14390b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 14400b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::const_reference 14410b57cec5SDimitry Andricvector<_Tp, _Allocator>::at(size_type __n) const 14420b57cec5SDimitry Andric{ 14430b57cec5SDimitry Andric if (__n >= size()) 14440b57cec5SDimitry Andric this->__throw_out_of_range(); 14450b57cec5SDimitry Andric return this->__begin_[__n]; 14460b57cec5SDimitry Andric} 14470b57cec5SDimitry Andric 14480b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 14490b57cec5SDimitry Andricvoid 14500b57cec5SDimitry Andricvector<_Tp, _Allocator>::reserve(size_type __n) 14510b57cec5SDimitry Andric{ 14520b57cec5SDimitry Andric if (__n > capacity()) 14530b57cec5SDimitry Andric { 1454349cc55cSDimitry Andric if (__n > max_size()) 1455349cc55cSDimitry Andric this->__throw_length_error(); 14560b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 14570b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__n, size(), __a); 14580b57cec5SDimitry Andric __swap_out_circular_buffer(__v); 14590b57cec5SDimitry Andric } 14600b57cec5SDimitry Andric} 14610b57cec5SDimitry Andric 14620b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 14630b57cec5SDimitry Andricvoid 14640b57cec5SDimitry Andricvector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT 14650b57cec5SDimitry Andric{ 14660b57cec5SDimitry Andric if (capacity() > size()) 14670b57cec5SDimitry Andric { 14680b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 14690b57cec5SDimitry Andric try 14700b57cec5SDimitry Andric { 14710b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 14720b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 14730b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(size(), size(), __a); 14740b57cec5SDimitry Andric __swap_out_circular_buffer(__v); 14750b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 14760b57cec5SDimitry Andric } 14770b57cec5SDimitry Andric catch (...) 14780b57cec5SDimitry Andric { 14790b57cec5SDimitry Andric } 14800b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 14810b57cec5SDimitry Andric } 14820b57cec5SDimitry Andric} 14830b57cec5SDimitry Andric 14840b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 14850b57cec5SDimitry Andrictemplate <class _Up> 14860b57cec5SDimitry Andricvoid 14870b57cec5SDimitry Andricvector<_Tp, _Allocator>::__push_back_slow_path(_Up&& __x) 14880b57cec5SDimitry Andric{ 14890b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 14900b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a); 14910b57cec5SDimitry Andric // __v.push_back(_VSTD::forward<_Up>(__x)); 1492480093f4SDimitry Andric __alloc_traits::construct(__a, _VSTD::__to_address(__v.__end_), _VSTD::forward<_Up>(__x)); 14930b57cec5SDimitry Andric __v.__end_++; 14940b57cec5SDimitry Andric __swap_out_circular_buffer(__v); 14950b57cec5SDimitry Andric} 14960b57cec5SDimitry Andric 14970b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 14980b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 14990b57cec5SDimitry Andricvoid 15000b57cec5SDimitry Andricvector<_Tp, _Allocator>::push_back(const_reference __x) 15010b57cec5SDimitry Andric{ 15020b57cec5SDimitry Andric if (this->__end_ != this->__end_cap()) 15030b57cec5SDimitry Andric { 1504e40139ffSDimitry Andric __construct_one_at_end(__x); 15050b57cec5SDimitry Andric } 15060b57cec5SDimitry Andric else 15070b57cec5SDimitry Andric __push_back_slow_path(__x); 15080b57cec5SDimitry Andric} 15090b57cec5SDimitry Andric 15100b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 15110b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 15120b57cec5SDimitry Andricvoid 15130b57cec5SDimitry Andricvector<_Tp, _Allocator>::push_back(value_type&& __x) 15140b57cec5SDimitry Andric{ 15150b57cec5SDimitry Andric if (this->__end_ < this->__end_cap()) 15160b57cec5SDimitry Andric { 1517e40139ffSDimitry Andric __construct_one_at_end(_VSTD::move(__x)); 15180b57cec5SDimitry Andric } 15190b57cec5SDimitry Andric else 15200b57cec5SDimitry Andric __push_back_slow_path(_VSTD::move(__x)); 15210b57cec5SDimitry Andric} 15220b57cec5SDimitry Andric 15230b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 15240b57cec5SDimitry Andrictemplate <class... _Args> 15250b57cec5SDimitry Andricvoid 15260b57cec5SDimitry Andricvector<_Tp, _Allocator>::__emplace_back_slow_path(_Args&&... __args) 15270b57cec5SDimitry Andric{ 15280b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 15290b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a); 15300b57cec5SDimitry Andric// __v.emplace_back(_VSTD::forward<_Args>(__args)...); 1531480093f4SDimitry Andric __alloc_traits::construct(__a, _VSTD::__to_address(__v.__end_), _VSTD::forward<_Args>(__args)...); 15320b57cec5SDimitry Andric __v.__end_++; 15330b57cec5SDimitry Andric __swap_out_circular_buffer(__v); 15340b57cec5SDimitry Andric} 15350b57cec5SDimitry Andric 15360b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 15370b57cec5SDimitry Andrictemplate <class... _Args> 15380b57cec5SDimitry Andricinline 15390b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 15400b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::reference 15410b57cec5SDimitry Andric#else 15420b57cec5SDimitry Andricvoid 15430b57cec5SDimitry Andric#endif 15440b57cec5SDimitry Andricvector<_Tp, _Allocator>::emplace_back(_Args&&... __args) 15450b57cec5SDimitry Andric{ 15460b57cec5SDimitry Andric if (this->__end_ < this->__end_cap()) 15470b57cec5SDimitry Andric { 1548e40139ffSDimitry Andric __construct_one_at_end(_VSTD::forward<_Args>(__args)...); 15490b57cec5SDimitry Andric } 15500b57cec5SDimitry Andric else 15510b57cec5SDimitry Andric __emplace_back_slow_path(_VSTD::forward<_Args>(__args)...); 15520b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 15530b57cec5SDimitry Andric return this->back(); 15540b57cec5SDimitry Andric#endif 15550b57cec5SDimitry Andric} 15560b57cec5SDimitry Andric 15570b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 15580b57cec5SDimitry Andricinline 15590b57cec5SDimitry Andricvoid 15600b57cec5SDimitry Andricvector<_Tp, _Allocator>::pop_back() 15610b57cec5SDimitry Andric{ 1562fe6060f1SDimitry Andric _LIBCPP_ASSERT(!empty(), "vector::pop_back called on an empty vector"); 15630b57cec5SDimitry Andric this->__destruct_at_end(this->__end_ - 1); 15640b57cec5SDimitry Andric} 15650b57cec5SDimitry Andric 15660b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 15670b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 15680b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator 15690b57cec5SDimitry Andricvector<_Tp, _Allocator>::erase(const_iterator __position) 15700b57cec5SDimitry Andric{ 157104eeddc0SDimitry Andric _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this, 157204eeddc0SDimitry Andric "vector::erase(iterator) called with an iterator not referring to this vector"); 15730b57cec5SDimitry Andric _LIBCPP_ASSERT(__position != end(), 15740b57cec5SDimitry Andric "vector::erase(iterator) called with a non-dereferenceable iterator"); 15750b57cec5SDimitry Andric difference_type __ps = __position - cbegin(); 15760b57cec5SDimitry Andric pointer __p = this->__begin_ + __ps; 15770b57cec5SDimitry Andric this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p)); 15780b57cec5SDimitry Andric this->__invalidate_iterators_past(__p-1); 1579*81ad6265SDimitry Andric iterator __r = iterator(this, __p); 15800b57cec5SDimitry Andric return __r; 15810b57cec5SDimitry Andric} 15820b57cec5SDimitry Andric 15830b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 15840b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator 15850b57cec5SDimitry Andricvector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last) 15860b57cec5SDimitry Andric{ 158704eeddc0SDimitry Andric _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__first)) == this, 158804eeddc0SDimitry Andric "vector::erase(iterator, iterator) called with an iterator not referring to this vector"); 158904eeddc0SDimitry Andric _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__last)) == this, 159004eeddc0SDimitry Andric "vector::erase(iterator, iterator) called with an iterator not referring to this vector"); 159104eeddc0SDimitry Andric 15920b57cec5SDimitry Andric _LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range"); 15930b57cec5SDimitry Andric pointer __p = this->__begin_ + (__first - begin()); 15940b57cec5SDimitry Andric if (__first != __last) { 15950b57cec5SDimitry Andric this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p)); 15960b57cec5SDimitry Andric this->__invalidate_iterators_past(__p - 1); 15970b57cec5SDimitry Andric } 1598*81ad6265SDimitry Andric iterator __r = iterator(this, __p); 15990b57cec5SDimitry Andric return __r; 16000b57cec5SDimitry Andric} 16010b57cec5SDimitry Andric 16020b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 16030b57cec5SDimitry Andricvoid 16040b57cec5SDimitry Andricvector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to) 16050b57cec5SDimitry Andric{ 16060b57cec5SDimitry Andric pointer __old_last = this->__end_; 16070b57cec5SDimitry Andric difference_type __n = __old_last - __to; 1608e40139ffSDimitry Andric { 1609e40139ffSDimitry Andric pointer __i = __from_s + __n; 1610e40139ffSDimitry Andric _ConstructTransaction __tx(*this, __from_e - __i); 16115ffd83dbSDimitry Andric for (pointer __pos = __tx.__pos_; __i < __from_e; 1612349cc55cSDimitry Andric ++__i, (void) ++__pos, __tx.__pos_ = __pos) { 16130b57cec5SDimitry Andric __alloc_traits::construct(this->__alloc(), 16145ffd83dbSDimitry Andric _VSTD::__to_address(__pos), 16150b57cec5SDimitry Andric _VSTD::move(*__i)); 1616e40139ffSDimitry Andric } 1617e40139ffSDimitry Andric } 16180b57cec5SDimitry Andric _VSTD::move_backward(__from_s, __from_s + __n, __old_last); 16190b57cec5SDimitry Andric} 16200b57cec5SDimitry Andric 16210b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 16220b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator 16230b57cec5SDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x) 16240b57cec5SDimitry Andric{ 162504eeddc0SDimitry Andric _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this, 162604eeddc0SDimitry Andric "vector::insert(iterator, x) called with an iterator not referring to this vector"); 16270b57cec5SDimitry Andric pointer __p = this->__begin_ + (__position - begin()); 16280b57cec5SDimitry Andric if (this->__end_ < this->__end_cap()) 16290b57cec5SDimitry Andric { 16300b57cec5SDimitry Andric if (__p == this->__end_) 16310b57cec5SDimitry Andric { 1632e40139ffSDimitry Andric __construct_one_at_end(__x); 16330b57cec5SDimitry Andric } 16340b57cec5SDimitry Andric else 16350b57cec5SDimitry Andric { 16360b57cec5SDimitry Andric __move_range(__p, this->__end_, __p + 1); 16370b57cec5SDimitry Andric const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x); 16380b57cec5SDimitry Andric if (__p <= __xr && __xr < this->__end_) 16390b57cec5SDimitry Andric ++__xr; 16400b57cec5SDimitry Andric *__p = *__xr; 16410b57cec5SDimitry Andric } 16420b57cec5SDimitry Andric } 16430b57cec5SDimitry Andric else 16440b57cec5SDimitry Andric { 16450b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 16460b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a); 16470b57cec5SDimitry Andric __v.push_back(__x); 16480b57cec5SDimitry Andric __p = __swap_out_circular_buffer(__v, __p); 16490b57cec5SDimitry Andric } 1650*81ad6265SDimitry Andric return iterator(this, __p); 16510b57cec5SDimitry Andric} 16520b57cec5SDimitry Andric 16530b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 16540b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator 16550b57cec5SDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x) 16560b57cec5SDimitry Andric{ 165704eeddc0SDimitry Andric _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this, 165804eeddc0SDimitry Andric "vector::insert(iterator, x) called with an iterator not referring to this vector"); 16590b57cec5SDimitry Andric pointer __p = this->__begin_ + (__position - begin()); 16600b57cec5SDimitry Andric if (this->__end_ < this->__end_cap()) 16610b57cec5SDimitry Andric { 16620b57cec5SDimitry Andric if (__p == this->__end_) 16630b57cec5SDimitry Andric { 1664e40139ffSDimitry Andric __construct_one_at_end(_VSTD::move(__x)); 16650b57cec5SDimitry Andric } 16660b57cec5SDimitry Andric else 16670b57cec5SDimitry Andric { 16680b57cec5SDimitry Andric __move_range(__p, this->__end_, __p + 1); 16690b57cec5SDimitry Andric *__p = _VSTD::move(__x); 16700b57cec5SDimitry Andric } 16710b57cec5SDimitry Andric } 16720b57cec5SDimitry Andric else 16730b57cec5SDimitry Andric { 16740b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 16750b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a); 16760b57cec5SDimitry Andric __v.push_back(_VSTD::move(__x)); 16770b57cec5SDimitry Andric __p = __swap_out_circular_buffer(__v, __p); 16780b57cec5SDimitry Andric } 1679*81ad6265SDimitry Andric return iterator(this, __p); 16800b57cec5SDimitry Andric} 16810b57cec5SDimitry Andric 16820b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 16830b57cec5SDimitry Andrictemplate <class... _Args> 16840b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator 16850b57cec5SDimitry Andricvector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args) 16860b57cec5SDimitry Andric{ 168704eeddc0SDimitry Andric _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this, 168804eeddc0SDimitry Andric "vector::emplace(iterator, x) called with an iterator not referring to this vector"); 16890b57cec5SDimitry Andric pointer __p = this->__begin_ + (__position - begin()); 16900b57cec5SDimitry Andric if (this->__end_ < this->__end_cap()) 16910b57cec5SDimitry Andric { 16920b57cec5SDimitry Andric if (__p == this->__end_) 16930b57cec5SDimitry Andric { 1694e40139ffSDimitry Andric __construct_one_at_end(_VSTD::forward<_Args>(__args)...); 16950b57cec5SDimitry Andric } 16960b57cec5SDimitry Andric else 16970b57cec5SDimitry Andric { 16980b57cec5SDimitry Andric __temp_value<value_type, _Allocator> __tmp(this->__alloc(), _VSTD::forward<_Args>(__args)...); 16990b57cec5SDimitry Andric __move_range(__p, this->__end_, __p + 1); 17000b57cec5SDimitry Andric *__p = _VSTD::move(__tmp.get()); 17010b57cec5SDimitry Andric } 17020b57cec5SDimitry Andric } 17030b57cec5SDimitry Andric else 17040b57cec5SDimitry Andric { 17050b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 17060b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a); 17070b57cec5SDimitry Andric __v.emplace_back(_VSTD::forward<_Args>(__args)...); 17080b57cec5SDimitry Andric __p = __swap_out_circular_buffer(__v, __p); 17090b57cec5SDimitry Andric } 1710*81ad6265SDimitry Andric return iterator(this, __p); 17110b57cec5SDimitry Andric} 17120b57cec5SDimitry Andric 17130b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 17140b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator 17150b57cec5SDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x) 17160b57cec5SDimitry Andric{ 171704eeddc0SDimitry Andric _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this, 171804eeddc0SDimitry Andric "vector::insert(iterator, n, x) called with an iterator not referring to this vector"); 17190b57cec5SDimitry Andric pointer __p = this->__begin_ + (__position - begin()); 17200b57cec5SDimitry Andric if (__n > 0) 17210b57cec5SDimitry Andric { 17220b57cec5SDimitry Andric if (__n <= static_cast<size_type>(this->__end_cap() - this->__end_)) 17230b57cec5SDimitry Andric { 17240b57cec5SDimitry Andric size_type __old_n = __n; 17250b57cec5SDimitry Andric pointer __old_last = this->__end_; 17260b57cec5SDimitry Andric if (__n > static_cast<size_type>(this->__end_ - __p)) 17270b57cec5SDimitry Andric { 17280b57cec5SDimitry Andric size_type __cx = __n - (this->__end_ - __p); 17290b57cec5SDimitry Andric __construct_at_end(__cx, __x); 17300b57cec5SDimitry Andric __n -= __cx; 17310b57cec5SDimitry Andric } 17320b57cec5SDimitry Andric if (__n > 0) 17330b57cec5SDimitry Andric { 17340b57cec5SDimitry Andric __move_range(__p, __old_last, __p + __old_n); 17350b57cec5SDimitry Andric const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x); 17360b57cec5SDimitry Andric if (__p <= __xr && __xr < this->__end_) 17370b57cec5SDimitry Andric __xr += __old_n; 17380b57cec5SDimitry Andric _VSTD::fill_n(__p, __n, *__xr); 17390b57cec5SDimitry Andric } 17400b57cec5SDimitry Andric } 17410b57cec5SDimitry Andric else 17420b57cec5SDimitry Andric { 17430b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 17440b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a); 17450b57cec5SDimitry Andric __v.__construct_at_end(__n, __x); 17460b57cec5SDimitry Andric __p = __swap_out_circular_buffer(__v, __p); 17470b57cec5SDimitry Andric } 17480b57cec5SDimitry Andric } 1749*81ad6265SDimitry Andric return iterator(this, __p); 17500b57cec5SDimitry Andric} 17510b57cec5SDimitry Andric 17520b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 17530b57cec5SDimitry Andrictemplate <class _InputIterator> 17540b57cec5SDimitry Andrictypename enable_if 17550b57cec5SDimitry Andric< 1756480093f4SDimitry Andric __is_cpp17_input_iterator <_InputIterator>::value && 1757480093f4SDimitry Andric !__is_cpp17_forward_iterator<_InputIterator>::value && 17580b57cec5SDimitry Andric is_constructible< 17590b57cec5SDimitry Andric _Tp, 17600b57cec5SDimitry Andric typename iterator_traits<_InputIterator>::reference>::value, 17610b57cec5SDimitry Andric typename vector<_Tp, _Allocator>::iterator 17620b57cec5SDimitry Andric>::type 17630b57cec5SDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last) 17640b57cec5SDimitry Andric{ 176504eeddc0SDimitry Andric _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this, 176604eeddc0SDimitry Andric "vector::insert(iterator, range) called with an iterator not referring to this vector"); 17670b57cec5SDimitry Andric difference_type __off = __position - begin(); 17680b57cec5SDimitry Andric pointer __p = this->__begin_ + __off; 17690b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 17700b57cec5SDimitry Andric pointer __old_last = this->__end_; 17710b57cec5SDimitry Andric for (; this->__end_ != this->__end_cap() && __first != __last; ++__first) 17720b57cec5SDimitry Andric { 1773e40139ffSDimitry Andric __construct_one_at_end(*__first); 17740b57cec5SDimitry Andric } 17750b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__a); 17760b57cec5SDimitry Andric if (__first != __last) 17770b57cec5SDimitry Andric { 17780b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 17790b57cec5SDimitry Andric try 17800b57cec5SDimitry Andric { 17810b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 17820b57cec5SDimitry Andric __v.__construct_at_end(__first, __last); 17830b57cec5SDimitry Andric difference_type __old_size = __old_last - this->__begin_; 17840b57cec5SDimitry Andric difference_type __old_p = __p - this->__begin_; 17850b57cec5SDimitry Andric reserve(__recommend(size() + __v.size())); 17860b57cec5SDimitry Andric __p = this->__begin_ + __old_p; 17870b57cec5SDimitry Andric __old_last = this->__begin_ + __old_size; 17880b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 17890b57cec5SDimitry Andric } 17900b57cec5SDimitry Andric catch (...) 17910b57cec5SDimitry Andric { 1792*81ad6265SDimitry Andric erase(iterator(this, __old_last), end()); 17930b57cec5SDimitry Andric throw; 17940b57cec5SDimitry Andric } 17950b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 17960b57cec5SDimitry Andric } 17970b57cec5SDimitry Andric __p = _VSTD::rotate(__p, __old_last, this->__end_); 1798*81ad6265SDimitry Andric insert(iterator(this, __p), _VSTD::make_move_iterator(__v.begin()), 17995ffd83dbSDimitry Andric _VSTD::make_move_iterator(__v.end())); 18000b57cec5SDimitry Andric return begin() + __off; 18010b57cec5SDimitry Andric} 18020b57cec5SDimitry Andric 18030b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 18040b57cec5SDimitry Andrictemplate <class _ForwardIterator> 18050b57cec5SDimitry Andrictypename enable_if 18060b57cec5SDimitry Andric< 1807480093f4SDimitry Andric __is_cpp17_forward_iterator<_ForwardIterator>::value && 18080b57cec5SDimitry Andric is_constructible< 18090b57cec5SDimitry Andric _Tp, 18100b57cec5SDimitry Andric typename iterator_traits<_ForwardIterator>::reference>::value, 18110b57cec5SDimitry Andric typename vector<_Tp, _Allocator>::iterator 18120b57cec5SDimitry Andric>::type 18130b57cec5SDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last) 18140b57cec5SDimitry Andric{ 181504eeddc0SDimitry Andric _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this, 181604eeddc0SDimitry Andric "vector::insert(iterator, range) called with an iterator not referring to this vector"); 18170b57cec5SDimitry Andric pointer __p = this->__begin_ + (__position - begin()); 18180b57cec5SDimitry Andric difference_type __n = _VSTD::distance(__first, __last); 18190b57cec5SDimitry Andric if (__n > 0) 18200b57cec5SDimitry Andric { 18210b57cec5SDimitry Andric if (__n <= this->__end_cap() - this->__end_) 18220b57cec5SDimitry Andric { 18230b57cec5SDimitry Andric size_type __old_n = __n; 18240b57cec5SDimitry Andric pointer __old_last = this->__end_; 18250b57cec5SDimitry Andric _ForwardIterator __m = __last; 18260b57cec5SDimitry Andric difference_type __dx = this->__end_ - __p; 18270b57cec5SDimitry Andric if (__n > __dx) 18280b57cec5SDimitry Andric { 18290b57cec5SDimitry Andric __m = __first; 18300b57cec5SDimitry Andric difference_type __diff = this->__end_ - __p; 18310b57cec5SDimitry Andric _VSTD::advance(__m, __diff); 18320b57cec5SDimitry Andric __construct_at_end(__m, __last, __n - __diff); 18330b57cec5SDimitry Andric __n = __dx; 18340b57cec5SDimitry Andric } 18350b57cec5SDimitry Andric if (__n > 0) 18360b57cec5SDimitry Andric { 18370b57cec5SDimitry Andric __move_range(__p, __old_last, __p + __old_n); 18380b57cec5SDimitry Andric _VSTD::copy(__first, __m, __p); 18390b57cec5SDimitry Andric } 18400b57cec5SDimitry Andric } 18410b57cec5SDimitry Andric else 18420b57cec5SDimitry Andric { 18430b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 18440b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a); 18450b57cec5SDimitry Andric __v.__construct_at_end(__first, __last); 18460b57cec5SDimitry Andric __p = __swap_out_circular_buffer(__v, __p); 18470b57cec5SDimitry Andric } 18480b57cec5SDimitry Andric } 1849*81ad6265SDimitry Andric return iterator(this, __p); 18500b57cec5SDimitry Andric} 18510b57cec5SDimitry Andric 18520b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 18530b57cec5SDimitry Andricvoid 18540b57cec5SDimitry Andricvector<_Tp, _Allocator>::resize(size_type __sz) 18550b57cec5SDimitry Andric{ 18560b57cec5SDimitry Andric size_type __cs = size(); 18570b57cec5SDimitry Andric if (__cs < __sz) 18580b57cec5SDimitry Andric this->__append(__sz - __cs); 18590b57cec5SDimitry Andric else if (__cs > __sz) 18600b57cec5SDimitry Andric this->__destruct_at_end(this->__begin_ + __sz); 18610b57cec5SDimitry Andric} 18620b57cec5SDimitry Andric 18630b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 18640b57cec5SDimitry Andricvoid 18650b57cec5SDimitry Andricvector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x) 18660b57cec5SDimitry Andric{ 18670b57cec5SDimitry Andric size_type __cs = size(); 18680b57cec5SDimitry Andric if (__cs < __sz) 18690b57cec5SDimitry Andric this->__append(__sz - __cs, __x); 18700b57cec5SDimitry Andric else if (__cs > __sz) 18710b57cec5SDimitry Andric this->__destruct_at_end(this->__begin_ + __sz); 18720b57cec5SDimitry Andric} 18730b57cec5SDimitry Andric 18740b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 18750b57cec5SDimitry Andricvoid 18760b57cec5SDimitry Andricvector<_Tp, _Allocator>::swap(vector& __x) 18770b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14 18780b57cec5SDimitry Andric _NOEXCEPT 18790b57cec5SDimitry Andric#else 18800b57cec5SDimitry Andric _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || 18810b57cec5SDimitry Andric __is_nothrow_swappable<allocator_type>::value) 18820b57cec5SDimitry Andric#endif 18830b57cec5SDimitry Andric{ 18840b57cec5SDimitry Andric _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value || 18850b57cec5SDimitry Andric this->__alloc() == __x.__alloc(), 18860b57cec5SDimitry Andric "vector::swap: Either propagate_on_container_swap must be true" 18870b57cec5SDimitry Andric " or the allocators must compare equal"); 18880b57cec5SDimitry Andric _VSTD::swap(this->__begin_, __x.__begin_); 18890b57cec5SDimitry Andric _VSTD::swap(this->__end_, __x.__end_); 18900b57cec5SDimitry Andric _VSTD::swap(this->__end_cap(), __x.__end_cap()); 1891e8d8bef9SDimitry Andric _VSTD::__swap_allocator(this->__alloc(), __x.__alloc(), 18920b57cec5SDimitry Andric integral_constant<bool,__alloc_traits::propagate_on_container_swap::value>()); 1893*81ad6265SDimitry Andric std::__debug_db_swap(this, std::addressof(__x)); 18940b57cec5SDimitry Andric} 18950b57cec5SDimitry Andric 18960b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 18970b57cec5SDimitry Andricbool 18980b57cec5SDimitry Andricvector<_Tp, _Allocator>::__invariants() const 18990b57cec5SDimitry Andric{ 19000b57cec5SDimitry Andric if (this->__begin_ == nullptr) 19010b57cec5SDimitry Andric { 19020b57cec5SDimitry Andric if (this->__end_ != nullptr || this->__end_cap() != nullptr) 19030b57cec5SDimitry Andric return false; 19040b57cec5SDimitry Andric } 19050b57cec5SDimitry Andric else 19060b57cec5SDimitry Andric { 19070b57cec5SDimitry Andric if (this->__begin_ > this->__end_) 19080b57cec5SDimitry Andric return false; 19090b57cec5SDimitry Andric if (this->__begin_ == this->__end_cap()) 19100b57cec5SDimitry Andric return false; 19110b57cec5SDimitry Andric if (this->__end_ > this->__end_cap()) 19120b57cec5SDimitry Andric return false; 19130b57cec5SDimitry Andric } 19140b57cec5SDimitry Andric return true; 19150b57cec5SDimitry Andric} 19160b57cec5SDimitry Andric 1917*81ad6265SDimitry Andric#ifdef _LIBCPP_ENABLE_DEBUG_MODE 19180b57cec5SDimitry Andric 19190b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 19200b57cec5SDimitry Andricbool 19210b57cec5SDimitry Andricvector<_Tp, _Allocator>::__dereferenceable(const const_iterator* __i) const 19220b57cec5SDimitry Andric{ 19230b57cec5SDimitry Andric return this->__begin_ <= __i->base() && __i->base() < this->__end_; 19240b57cec5SDimitry Andric} 19250b57cec5SDimitry Andric 19260b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 19270b57cec5SDimitry Andricbool 19280b57cec5SDimitry Andricvector<_Tp, _Allocator>::__decrementable(const const_iterator* __i) const 19290b57cec5SDimitry Andric{ 19300b57cec5SDimitry Andric return this->__begin_ < __i->base() && __i->base() <= this->__end_; 19310b57cec5SDimitry Andric} 19320b57cec5SDimitry Andric 19330b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 19340b57cec5SDimitry Andricbool 19350b57cec5SDimitry Andricvector<_Tp, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const 19360b57cec5SDimitry Andric{ 19370b57cec5SDimitry Andric const_pointer __p = __i->base() + __n; 19380b57cec5SDimitry Andric return this->__begin_ <= __p && __p <= this->__end_; 19390b57cec5SDimitry Andric} 19400b57cec5SDimitry Andric 19410b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 19420b57cec5SDimitry Andricbool 19430b57cec5SDimitry Andricvector<_Tp, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const 19440b57cec5SDimitry Andric{ 19450b57cec5SDimitry Andric const_pointer __p = __i->base() + __n; 19460b57cec5SDimitry Andric return this->__begin_ <= __p && __p < this->__end_; 19470b57cec5SDimitry Andric} 19480b57cec5SDimitry Andric 1949*81ad6265SDimitry Andric#endif // _LIBCPP_ENABLE_DEBUG_MODE 19500b57cec5SDimitry Andric 19510b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 19520b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 19530b57cec5SDimitry Andricvoid 19540b57cec5SDimitry Andricvector<_Tp, _Allocator>::__invalidate_iterators_past(pointer __new_last) { 1955*81ad6265SDimitry Andric#ifdef _LIBCPP_ENABLE_DEBUG_MODE 19560b57cec5SDimitry Andric __c_node* __c = __get_db()->__find_c_and_lock(this); 19570b57cec5SDimitry Andric for (__i_node** __p = __c->end_; __p != __c->beg_; ) { 19580b57cec5SDimitry Andric --__p; 19590b57cec5SDimitry Andric const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_); 19600b57cec5SDimitry Andric if (__i->base() > __new_last) { 19610b57cec5SDimitry Andric (*__p)->__c_ = nullptr; 19620b57cec5SDimitry Andric if (--__c->end_ != __p) 1963e8d8bef9SDimitry Andric _VSTD::memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); 19640b57cec5SDimitry Andric } 19650b57cec5SDimitry Andric } 19660b57cec5SDimitry Andric __get_db()->unlock(); 19670b57cec5SDimitry Andric#else 19680b57cec5SDimitry Andric ((void)__new_last); 19690b57cec5SDimitry Andric#endif 19700b57cec5SDimitry Andric} 19710b57cec5SDimitry Andric 19720b57cec5SDimitry Andric// vector<bool> 19730b57cec5SDimitry Andric 19740b57cec5SDimitry Andrictemplate <class _Allocator> class vector<bool, _Allocator>; 19750b57cec5SDimitry Andric 19760b57cec5SDimitry Andrictemplate <class _Allocator> struct hash<vector<bool, _Allocator> >; 19770b57cec5SDimitry Andric 19780b57cec5SDimitry Andrictemplate <class _Allocator> 19790b57cec5SDimitry Andricstruct __has_storage_type<vector<bool, _Allocator> > 19800b57cec5SDimitry Andric{ 19810b57cec5SDimitry Andric static const bool value = true; 19820b57cec5SDimitry Andric}; 19830b57cec5SDimitry Andric 19840b57cec5SDimitry Andrictemplate <class _Allocator> 19850b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS vector<bool, _Allocator> 19860b57cec5SDimitry Andric{ 19870b57cec5SDimitry Andricpublic: 19880b57cec5SDimitry Andric typedef vector __self; 19890b57cec5SDimitry Andric typedef bool value_type; 19900b57cec5SDimitry Andric typedef _Allocator allocator_type; 19910b57cec5SDimitry Andric typedef allocator_traits<allocator_type> __alloc_traits; 19920b57cec5SDimitry Andric typedef typename __alloc_traits::size_type size_type; 19930b57cec5SDimitry Andric typedef typename __alloc_traits::difference_type difference_type; 19940b57cec5SDimitry Andric typedef size_type __storage_type; 19950b57cec5SDimitry Andric typedef __bit_iterator<vector, false> pointer; 19960b57cec5SDimitry Andric typedef __bit_iterator<vector, true> const_pointer; 19970b57cec5SDimitry Andric typedef pointer iterator; 19980b57cec5SDimitry Andric typedef const_pointer const_iterator; 19990b57cec5SDimitry Andric typedef _VSTD::reverse_iterator<iterator> reverse_iterator; 20000b57cec5SDimitry Andric typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; 20010b57cec5SDimitry Andric 20020b57cec5SDimitry Andricprivate: 20030b57cec5SDimitry Andric typedef typename __rebind_alloc_helper<__alloc_traits, __storage_type>::type __storage_allocator; 20040b57cec5SDimitry Andric typedef allocator_traits<__storage_allocator> __storage_traits; 20050b57cec5SDimitry Andric typedef typename __storage_traits::pointer __storage_pointer; 20060b57cec5SDimitry Andric typedef typename __storage_traits::const_pointer __const_storage_pointer; 20070b57cec5SDimitry Andric 20080b57cec5SDimitry Andric __storage_pointer __begin_; 20090b57cec5SDimitry Andric size_type __size_; 20100b57cec5SDimitry Andric __compressed_pair<size_type, __storage_allocator> __cap_alloc_; 20110b57cec5SDimitry Andricpublic: 20120b57cec5SDimitry Andric typedef __bit_reference<vector> reference; 2013*81ad6265SDimitry Andric#ifdef _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL 2014*81ad6265SDimitry Andric using const_reference = bool; 2015*81ad6265SDimitry Andric#else 20160b57cec5SDimitry Andric typedef __bit_const_reference<vector> const_reference; 2017*81ad6265SDimitry Andric#endif 20180b57cec5SDimitry Andricprivate: 20190b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 20200b57cec5SDimitry Andric size_type& __cap() _NOEXCEPT 20210b57cec5SDimitry Andric {return __cap_alloc_.first();} 20220b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 20230b57cec5SDimitry Andric const size_type& __cap() const _NOEXCEPT 20240b57cec5SDimitry Andric {return __cap_alloc_.first();} 20250b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 20260b57cec5SDimitry Andric __storage_allocator& __alloc() _NOEXCEPT 20270b57cec5SDimitry Andric {return __cap_alloc_.second();} 20280b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 20290b57cec5SDimitry Andric const __storage_allocator& __alloc() const _NOEXCEPT 20300b57cec5SDimitry Andric {return __cap_alloc_.second();} 20310b57cec5SDimitry Andric 20320b57cec5SDimitry Andric static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); 20330b57cec5SDimitry Andric 20340b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 20350b57cec5SDimitry Andric static size_type __internal_cap_to_external(size_type __n) _NOEXCEPT 20360b57cec5SDimitry Andric {return __n * __bits_per_word;} 20370b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 20380b57cec5SDimitry Andric static size_type __external_cap_to_internal(size_type __n) _NOEXCEPT 20390b57cec5SDimitry Andric {return (__n - 1) / __bits_per_word + 1;} 20400b57cec5SDimitry Andric 20410b57cec5SDimitry Andricpublic: 20420b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 20430b57cec5SDimitry Andric vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value); 20440b57cec5SDimitry Andric 20450b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a) 20460b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14 20470b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value); 20480b57cec5SDimitry Andric#else 20490b57cec5SDimitry Andric _NOEXCEPT; 20500b57cec5SDimitry Andric#endif 20510b57cec5SDimitry Andric ~vector(); 20520b57cec5SDimitry Andric explicit vector(size_type __n); 20530b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 20540b57cec5SDimitry Andric explicit vector(size_type __n, const allocator_type& __a); 20550b57cec5SDimitry Andric#endif 20560b57cec5SDimitry Andric vector(size_type __n, const value_type& __v); 20570b57cec5SDimitry Andric vector(size_type __n, const value_type& __v, const allocator_type& __a); 20580b57cec5SDimitry Andric template <class _InputIterator> 20590b57cec5SDimitry Andric vector(_InputIterator __first, _InputIterator __last, 2060480093f4SDimitry Andric typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value && 2061480093f4SDimitry Andric !__is_cpp17_forward_iterator<_InputIterator>::value>::type* = 0); 20620b57cec5SDimitry Andric template <class _InputIterator> 20630b57cec5SDimitry Andric vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, 2064480093f4SDimitry Andric typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value && 2065480093f4SDimitry Andric !__is_cpp17_forward_iterator<_InputIterator>::value>::type* = 0); 20660b57cec5SDimitry Andric template <class _ForwardIterator> 20670b57cec5SDimitry Andric vector(_ForwardIterator __first, _ForwardIterator __last, 2068480093f4SDimitry Andric typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type* = 0); 20690b57cec5SDimitry Andric template <class _ForwardIterator> 20700b57cec5SDimitry Andric vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, 2071480093f4SDimitry Andric typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type* = 0); 20720b57cec5SDimitry Andric 20730b57cec5SDimitry Andric vector(const vector& __v); 20740b57cec5SDimitry Andric vector(const vector& __v, const allocator_type& __a); 20750b57cec5SDimitry Andric vector& operator=(const vector& __v); 20760b57cec5SDimitry Andric 20770b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 20780b57cec5SDimitry Andric vector(initializer_list<value_type> __il); 20790b57cec5SDimitry Andric vector(initializer_list<value_type> __il, const allocator_type& __a); 20800b57cec5SDimitry Andric 20810b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 20820b57cec5SDimitry Andric vector& operator=(initializer_list<value_type> __il) 20830b57cec5SDimitry Andric {assign(__il.begin(), __il.end()); return *this;} 20840b57cec5SDimitry Andric 20850b57cec5SDimitry Andric#endif // !_LIBCPP_CXX03_LANG 20860b57cec5SDimitry Andric 2087*81ad6265SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2088*81ad6265SDimitry Andric vector(vector&& __v) 2089*81ad6265SDimitry Andric#if _LIBCPP_STD_VER > 14 2090*81ad6265SDimitry Andric noexcept; 2091*81ad6265SDimitry Andric#else 2092*81ad6265SDimitry Andric _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); 2093*81ad6265SDimitry Andric#endif 2094*81ad6265SDimitry Andric vector(vector&& __v, const __type_identity_t<allocator_type>& __a); 2095*81ad6265SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2096*81ad6265SDimitry Andric vector& operator=(vector&& __v) 2097*81ad6265SDimitry Andric _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)); 2098*81ad6265SDimitry Andric 20990b57cec5SDimitry Andric template <class _InputIterator> 21000b57cec5SDimitry Andric typename enable_if 21010b57cec5SDimitry Andric < 2102480093f4SDimitry Andric __is_cpp17_input_iterator<_InputIterator>::value && 2103480093f4SDimitry Andric !__is_cpp17_forward_iterator<_InputIterator>::value, 21040b57cec5SDimitry Andric void 21050b57cec5SDimitry Andric >::type 21060b57cec5SDimitry Andric assign(_InputIterator __first, _InputIterator __last); 21070b57cec5SDimitry Andric template <class _ForwardIterator> 21080b57cec5SDimitry Andric typename enable_if 21090b57cec5SDimitry Andric < 2110480093f4SDimitry Andric __is_cpp17_forward_iterator<_ForwardIterator>::value, 21110b57cec5SDimitry Andric void 21120b57cec5SDimitry Andric >::type 21130b57cec5SDimitry Andric assign(_ForwardIterator __first, _ForwardIterator __last); 21140b57cec5SDimitry Andric 21150b57cec5SDimitry Andric void assign(size_type __n, const value_type& __x); 21160b57cec5SDimitry Andric 21170b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 21180b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 21190b57cec5SDimitry Andric void assign(initializer_list<value_type> __il) 21200b57cec5SDimitry Andric {assign(__il.begin(), __il.end());} 21210b57cec5SDimitry Andric#endif 21220b57cec5SDimitry Andric 21230b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT 21240b57cec5SDimitry Andric {return allocator_type(this->__alloc());} 21250b57cec5SDimitry Andric 21260b57cec5SDimitry Andric size_type max_size() const _NOEXCEPT; 21270b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 21280b57cec5SDimitry Andric size_type capacity() const _NOEXCEPT 21290b57cec5SDimitry Andric {return __internal_cap_to_external(__cap());} 21300b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 21310b57cec5SDimitry Andric size_type size() const _NOEXCEPT 21320b57cec5SDimitry Andric {return __size_;} 21330b57cec5SDimitry Andric _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 21340b57cec5SDimitry Andric bool empty() const _NOEXCEPT 21350b57cec5SDimitry Andric {return __size_ == 0;} 21360b57cec5SDimitry Andric void reserve(size_type __n); 21370b57cec5SDimitry Andric void shrink_to_fit() _NOEXCEPT; 21380b57cec5SDimitry Andric 21390b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 21400b57cec5SDimitry Andric iterator begin() _NOEXCEPT 21410b57cec5SDimitry Andric {return __make_iter(0);} 21420b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 21430b57cec5SDimitry Andric const_iterator begin() const _NOEXCEPT 21440b57cec5SDimitry Andric {return __make_iter(0);} 21450b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 21460b57cec5SDimitry Andric iterator end() _NOEXCEPT 21470b57cec5SDimitry Andric {return __make_iter(__size_);} 21480b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 21490b57cec5SDimitry Andric const_iterator end() const _NOEXCEPT 21500b57cec5SDimitry Andric {return __make_iter(__size_);} 21510b57cec5SDimitry Andric 21520b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 21530b57cec5SDimitry Andric reverse_iterator rbegin() _NOEXCEPT 21540b57cec5SDimitry Andric {return reverse_iterator(end());} 21550b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 21560b57cec5SDimitry Andric const_reverse_iterator rbegin() const _NOEXCEPT 21570b57cec5SDimitry Andric {return const_reverse_iterator(end());} 21580b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 21590b57cec5SDimitry Andric reverse_iterator rend() _NOEXCEPT 21600b57cec5SDimitry Andric {return reverse_iterator(begin());} 21610b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 21620b57cec5SDimitry Andric const_reverse_iterator rend() const _NOEXCEPT 21630b57cec5SDimitry Andric {return const_reverse_iterator(begin());} 21640b57cec5SDimitry Andric 21650b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 21660b57cec5SDimitry Andric const_iterator cbegin() const _NOEXCEPT 21670b57cec5SDimitry Andric {return __make_iter(0);} 21680b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 21690b57cec5SDimitry Andric const_iterator cend() const _NOEXCEPT 21700b57cec5SDimitry Andric {return __make_iter(__size_);} 21710b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 21720b57cec5SDimitry Andric const_reverse_iterator crbegin() const _NOEXCEPT 21730b57cec5SDimitry Andric {return rbegin();} 21740b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 21750b57cec5SDimitry Andric const_reverse_iterator crend() const _NOEXCEPT 21760b57cec5SDimitry Andric {return rend();} 21770b57cec5SDimitry Andric 21780b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) {return __make_ref(__n);} 21790b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const {return __make_ref(__n);} 21800b57cec5SDimitry Andric reference at(size_type __n); 21810b57cec5SDimitry Andric const_reference at(size_type __n) const; 21820b57cec5SDimitry Andric 21830b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY reference front() {return __make_ref(0);} 21840b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY const_reference front() const {return __make_ref(0);} 21850b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY reference back() {return __make_ref(__size_ - 1);} 21860b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY const_reference back() const {return __make_ref(__size_ - 1);} 21870b57cec5SDimitry Andric 21880b57cec5SDimitry Andric void push_back(const value_type& __x); 21890b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 21900b57cec5SDimitry Andric template <class... _Args> 21910b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 21920b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY reference emplace_back(_Args&&... __args) 21930b57cec5SDimitry Andric#else 21940b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY void emplace_back(_Args&&... __args) 21950b57cec5SDimitry Andric#endif 21960b57cec5SDimitry Andric { 21970b57cec5SDimitry Andric push_back ( value_type ( _VSTD::forward<_Args>(__args)... )); 21980b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 21990b57cec5SDimitry Andric return this->back(); 22000b57cec5SDimitry Andric#endif 22010b57cec5SDimitry Andric } 22020b57cec5SDimitry Andric#endif 22030b57cec5SDimitry Andric 22040b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY void pop_back() {--__size_;} 22050b57cec5SDimitry Andric 22060b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 22070b57cec5SDimitry Andric template <class... _Args> 22080b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY iterator emplace(const_iterator position, _Args&&... __args) 22090b57cec5SDimitry Andric { return insert ( position, value_type ( _VSTD::forward<_Args>(__args)... )); } 22100b57cec5SDimitry Andric#endif 22110b57cec5SDimitry Andric 22120b57cec5SDimitry Andric iterator insert(const_iterator __position, const value_type& __x); 22130b57cec5SDimitry Andric iterator insert(const_iterator __position, size_type __n, const value_type& __x); 22140b57cec5SDimitry Andric template <class _InputIterator> 22150b57cec5SDimitry Andric typename enable_if 22160b57cec5SDimitry Andric < 2217480093f4SDimitry Andric __is_cpp17_input_iterator <_InputIterator>::value && 2218480093f4SDimitry Andric !__is_cpp17_forward_iterator<_InputIterator>::value, 22190b57cec5SDimitry Andric iterator 22200b57cec5SDimitry Andric >::type 22210b57cec5SDimitry Andric insert(const_iterator __position, _InputIterator __first, _InputIterator __last); 22220b57cec5SDimitry Andric template <class _ForwardIterator> 22230b57cec5SDimitry Andric typename enable_if 22240b57cec5SDimitry Andric < 2225480093f4SDimitry Andric __is_cpp17_forward_iterator<_ForwardIterator>::value, 22260b57cec5SDimitry Andric iterator 22270b57cec5SDimitry Andric >::type 22280b57cec5SDimitry Andric insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last); 22290b57cec5SDimitry Andric 22300b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 22310b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 22320b57cec5SDimitry Andric iterator insert(const_iterator __position, initializer_list<value_type> __il) 22330b57cec5SDimitry Andric {return insert(__position, __il.begin(), __il.end());} 22340b57cec5SDimitry Andric#endif 22350b57cec5SDimitry Andric 22360b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position); 22370b57cec5SDimitry Andric iterator erase(const_iterator __first, const_iterator __last); 22380b57cec5SDimitry Andric 22390b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 22400b57cec5SDimitry Andric void clear() _NOEXCEPT {__size_ = 0;} 22410b57cec5SDimitry Andric 22420b57cec5SDimitry Andric void swap(vector&) 22430b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14 22440b57cec5SDimitry Andric _NOEXCEPT; 22450b57cec5SDimitry Andric#else 22460b57cec5SDimitry Andric _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || 22470b57cec5SDimitry Andric __is_nothrow_swappable<allocator_type>::value); 22480b57cec5SDimitry Andric#endif 22490b57cec5SDimitry Andric static void swap(reference __x, reference __y) _NOEXCEPT { _VSTD::swap(__x, __y); } 22500b57cec5SDimitry Andric 22510b57cec5SDimitry Andric void resize(size_type __sz, value_type __x = false); 22520b57cec5SDimitry Andric void flip() _NOEXCEPT; 22530b57cec5SDimitry Andric 22540b57cec5SDimitry Andric bool __invariants() const; 22550b57cec5SDimitry Andric 22560b57cec5SDimitry Andricprivate: 2257d56accc7SDimitry Andric _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI 2258d56accc7SDimitry Andric void __throw_length_error() const { 2259d56accc7SDimitry Andric _VSTD::__throw_length_error("vector"); 2260d56accc7SDimitry Andric } 2261d56accc7SDimitry Andric 2262d56accc7SDimitry Andric _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI 2263d56accc7SDimitry Andric void __throw_out_of_range() const { 2264d56accc7SDimitry Andric _VSTD::__throw_out_of_range("vector"); 2265d56accc7SDimitry Andric } 2266d56accc7SDimitry Andric 2267*81ad6265SDimitry Andric // Allocate space for __n objects 2268*81ad6265SDimitry Andric // throws length_error if __n > max_size() 2269*81ad6265SDimitry Andric // throws (probably bad_alloc) if memory run out 2270*81ad6265SDimitry Andric // Precondition: __begin_ == __end_ == __cap() == 0 2271*81ad6265SDimitry Andric // Precondition: __n > 0 2272*81ad6265SDimitry Andric // Postcondition: capacity() >= __n 2273*81ad6265SDimitry Andric // Postcondition: size() == 0 2274*81ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI void __vallocate(size_type __n) { 2275*81ad6265SDimitry Andric if (__n > max_size()) 2276*81ad6265SDimitry Andric __throw_length_error(); 2277*81ad6265SDimitry Andric auto __allocation = std::__allocate_at_least(__alloc(), __external_cap_to_internal(__n)); 2278*81ad6265SDimitry Andric __begin_ = __allocation.ptr; 2279*81ad6265SDimitry Andric __size_ = 0; 2280*81ad6265SDimitry Andric __cap() = __allocation.count; 2281*81ad6265SDimitry Andric } 2282*81ad6265SDimitry Andric 22830b57cec5SDimitry Andric void __vdeallocate() _NOEXCEPT; 22840b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 22850b57cec5SDimitry Andric static size_type __align_it(size_type __new_size) _NOEXCEPT 2286*81ad6265SDimitry Andric {return (__new_size + (__bits_per_word-1)) & ~((size_type)__bits_per_word-1);} 22870b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const; 22880b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY void __construct_at_end(size_type __n, bool __x); 22890b57cec5SDimitry Andric template <class _ForwardIterator> 22900b57cec5SDimitry Andric typename enable_if 22910b57cec5SDimitry Andric < 2292480093f4SDimitry Andric __is_cpp17_forward_iterator<_ForwardIterator>::value, 22930b57cec5SDimitry Andric void 22940b57cec5SDimitry Andric >::type 22950b57cec5SDimitry Andric __construct_at_end(_ForwardIterator __first, _ForwardIterator __last); 22960b57cec5SDimitry Andric void __append(size_type __n, const_reference __x); 22970b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 22980b57cec5SDimitry Andric reference __make_ref(size_type __pos) _NOEXCEPT 22990b57cec5SDimitry Andric {return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);} 23000b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2301*81ad6265SDimitry Andric const_reference __make_ref(size_type __pos) const _NOEXCEPT { 2302*81ad6265SDimitry Andric return __bit_const_reference<vector>(__begin_ + __pos / __bits_per_word, 2303*81ad6265SDimitry Andric __storage_type(1) << __pos % __bits_per_word); 2304*81ad6265SDimitry Andric } 23050b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 23060b57cec5SDimitry Andric iterator __make_iter(size_type __pos) _NOEXCEPT 23070b57cec5SDimitry Andric {return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));} 23080b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 23090b57cec5SDimitry Andric const_iterator __make_iter(size_type __pos) const _NOEXCEPT 23100b57cec5SDimitry Andric {return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));} 23110b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 23120b57cec5SDimitry Andric iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT 23130b57cec5SDimitry Andric {return begin() + (__p - cbegin());} 23140b57cec5SDimitry Andric 23150b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 23160b57cec5SDimitry Andric void __copy_assign_alloc(const vector& __v) 23170b57cec5SDimitry Andric {__copy_assign_alloc(__v, integral_constant<bool, 23180b57cec5SDimitry Andric __storage_traits::propagate_on_container_copy_assignment::value>());} 23190b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 23200b57cec5SDimitry Andric void __copy_assign_alloc(const vector& __c, true_type) 23210b57cec5SDimitry Andric { 23220b57cec5SDimitry Andric if (__alloc() != __c.__alloc()) 23230b57cec5SDimitry Andric __vdeallocate(); 23240b57cec5SDimitry Andric __alloc() = __c.__alloc(); 23250b57cec5SDimitry Andric } 23260b57cec5SDimitry Andric 23270b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 23280b57cec5SDimitry Andric void __copy_assign_alloc(const vector&, false_type) 23290b57cec5SDimitry Andric {} 23300b57cec5SDimitry Andric 23310b57cec5SDimitry Andric void __move_assign(vector& __c, false_type); 23320b57cec5SDimitry Andric void __move_assign(vector& __c, true_type) 23330b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); 23340b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 23350b57cec5SDimitry Andric void __move_assign_alloc(vector& __c) 23360b57cec5SDimitry Andric _NOEXCEPT_( 23370b57cec5SDimitry Andric !__storage_traits::propagate_on_container_move_assignment::value || 23380b57cec5SDimitry Andric is_nothrow_move_assignable<allocator_type>::value) 23390b57cec5SDimitry Andric {__move_assign_alloc(__c, integral_constant<bool, 23400b57cec5SDimitry Andric __storage_traits::propagate_on_container_move_assignment::value>());} 23410b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 23420b57cec5SDimitry Andric void __move_assign_alloc(vector& __c, true_type) 23430b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) 23440b57cec5SDimitry Andric { 23450b57cec5SDimitry Andric __alloc() = _VSTD::move(__c.__alloc()); 23460b57cec5SDimitry Andric } 23470b57cec5SDimitry Andric 23480b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 23490b57cec5SDimitry Andric void __move_assign_alloc(vector&, false_type) 23500b57cec5SDimitry Andric _NOEXCEPT 23510b57cec5SDimitry Andric {} 23520b57cec5SDimitry Andric 23530b57cec5SDimitry Andric size_t __hash_code() const _NOEXCEPT; 23540b57cec5SDimitry Andric 23550b57cec5SDimitry Andric friend class __bit_reference<vector>; 23560b57cec5SDimitry Andric friend class __bit_const_reference<vector>; 23570b57cec5SDimitry Andric friend class __bit_iterator<vector, false>; 23580b57cec5SDimitry Andric friend class __bit_iterator<vector, true>; 23590b57cec5SDimitry Andric friend struct __bit_array<vector>; 23600b57cec5SDimitry Andric friend struct _LIBCPP_TEMPLATE_VIS hash<vector>; 23610b57cec5SDimitry Andric}; 23620b57cec5SDimitry Andric 23630b57cec5SDimitry Andrictemplate <class _Allocator> 23640b57cec5SDimitry Andricvoid 23650b57cec5SDimitry Andricvector<bool, _Allocator>::__vdeallocate() _NOEXCEPT 23660b57cec5SDimitry Andric{ 23670b57cec5SDimitry Andric if (this->__begin_ != nullptr) 23680b57cec5SDimitry Andric { 23690b57cec5SDimitry Andric __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap()); 2370*81ad6265SDimitry Andric std::__debug_db_invalidate_all(this); 23710b57cec5SDimitry Andric this->__begin_ = nullptr; 23720b57cec5SDimitry Andric this->__size_ = this->__cap() = 0; 23730b57cec5SDimitry Andric } 23740b57cec5SDimitry Andric} 23750b57cec5SDimitry Andric 23760b57cec5SDimitry Andrictemplate <class _Allocator> 23770b57cec5SDimitry Andrictypename vector<bool, _Allocator>::size_type 23780b57cec5SDimitry Andricvector<bool, _Allocator>::max_size() const _NOEXCEPT 23790b57cec5SDimitry Andric{ 23800b57cec5SDimitry Andric size_type __amax = __storage_traits::max_size(__alloc()); 23810b57cec5SDimitry Andric size_type __nmax = numeric_limits<size_type>::max() / 2; // end() >= begin(), always 23820b57cec5SDimitry Andric if (__nmax / __bits_per_word <= __amax) 23830b57cec5SDimitry Andric return __nmax; 23840b57cec5SDimitry Andric return __internal_cap_to_external(__amax); 23850b57cec5SDimitry Andric} 23860b57cec5SDimitry Andric 23870b57cec5SDimitry Andric// Precondition: __new_size > capacity() 23880b57cec5SDimitry Andrictemplate <class _Allocator> 23890b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 23900b57cec5SDimitry Andrictypename vector<bool, _Allocator>::size_type 23910b57cec5SDimitry Andricvector<bool, _Allocator>::__recommend(size_type __new_size) const 23920b57cec5SDimitry Andric{ 23930b57cec5SDimitry Andric const size_type __ms = max_size(); 23940b57cec5SDimitry Andric if (__new_size > __ms) 23950b57cec5SDimitry Andric this->__throw_length_error(); 23960b57cec5SDimitry Andric const size_type __cap = capacity(); 23970b57cec5SDimitry Andric if (__cap >= __ms / 2) 23980b57cec5SDimitry Andric return __ms; 23990b57cec5SDimitry Andric return _VSTD::max(2 * __cap, __align_it(__new_size)); 24000b57cec5SDimitry Andric} 24010b57cec5SDimitry Andric 24020b57cec5SDimitry Andric// Default constructs __n objects starting at __end_ 24030b57cec5SDimitry Andric// Precondition: __n > 0 24040b57cec5SDimitry Andric// Precondition: size() + __n <= capacity() 24050b57cec5SDimitry Andric// Postcondition: size() == size() + __n 24060b57cec5SDimitry Andrictemplate <class _Allocator> 24070b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 24080b57cec5SDimitry Andricvoid 24090b57cec5SDimitry Andricvector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x) 24100b57cec5SDimitry Andric{ 24110b57cec5SDimitry Andric size_type __old_size = this->__size_; 24120b57cec5SDimitry Andric this->__size_ += __n; 24130b57cec5SDimitry Andric if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word)) 24140b57cec5SDimitry Andric { 24150b57cec5SDimitry Andric if (this->__size_ <= __bits_per_word) 24160b57cec5SDimitry Andric this->__begin_[0] = __storage_type(0); 24170b57cec5SDimitry Andric else 24180b57cec5SDimitry Andric this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0); 24190b57cec5SDimitry Andric } 24200b57cec5SDimitry Andric _VSTD::fill_n(__make_iter(__old_size), __n, __x); 24210b57cec5SDimitry Andric} 24220b57cec5SDimitry Andric 24230b57cec5SDimitry Andrictemplate <class _Allocator> 24240b57cec5SDimitry Andrictemplate <class _ForwardIterator> 24250b57cec5SDimitry Andrictypename enable_if 24260b57cec5SDimitry Andric< 2427480093f4SDimitry Andric __is_cpp17_forward_iterator<_ForwardIterator>::value, 24280b57cec5SDimitry Andric void 24290b57cec5SDimitry Andric>::type 24300b57cec5SDimitry Andricvector<bool, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last) 24310b57cec5SDimitry Andric{ 24320b57cec5SDimitry Andric size_type __old_size = this->__size_; 24330b57cec5SDimitry Andric this->__size_ += _VSTD::distance(__first, __last); 24340b57cec5SDimitry Andric if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word)) 24350b57cec5SDimitry Andric { 24360b57cec5SDimitry Andric if (this->__size_ <= __bits_per_word) 24370b57cec5SDimitry Andric this->__begin_[0] = __storage_type(0); 24380b57cec5SDimitry Andric else 24390b57cec5SDimitry Andric this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0); 24400b57cec5SDimitry Andric } 24410b57cec5SDimitry Andric _VSTD::copy(__first, __last, __make_iter(__old_size)); 24420b57cec5SDimitry Andric} 24430b57cec5SDimitry Andric 24440b57cec5SDimitry Andrictemplate <class _Allocator> 24450b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 24460b57cec5SDimitry Andricvector<bool, _Allocator>::vector() 24470b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) 24480b57cec5SDimitry Andric : __begin_(nullptr), 24490b57cec5SDimitry Andric __size_(0), 2450480093f4SDimitry Andric __cap_alloc_(0, __default_init_tag()) 24510b57cec5SDimitry Andric{ 24520b57cec5SDimitry Andric} 24530b57cec5SDimitry Andric 24540b57cec5SDimitry Andrictemplate <class _Allocator> 24550b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 24560b57cec5SDimitry Andricvector<bool, _Allocator>::vector(const allocator_type& __a) 24570b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14 24580b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value) 24590b57cec5SDimitry Andric#else 24600b57cec5SDimitry Andric _NOEXCEPT 24610b57cec5SDimitry Andric#endif 24620b57cec5SDimitry Andric : __begin_(nullptr), 24630b57cec5SDimitry Andric __size_(0), 24640b57cec5SDimitry Andric __cap_alloc_(0, static_cast<__storage_allocator>(__a)) 24650b57cec5SDimitry Andric{ 24660b57cec5SDimitry Andric} 24670b57cec5SDimitry Andric 24680b57cec5SDimitry Andrictemplate <class _Allocator> 24690b57cec5SDimitry Andricvector<bool, _Allocator>::vector(size_type __n) 24700b57cec5SDimitry Andric : __begin_(nullptr), 24710b57cec5SDimitry Andric __size_(0), 2472480093f4SDimitry Andric __cap_alloc_(0, __default_init_tag()) 24730b57cec5SDimitry Andric{ 24740b57cec5SDimitry Andric if (__n > 0) 24750b57cec5SDimitry Andric { 24760b57cec5SDimitry Andric __vallocate(__n); 24770b57cec5SDimitry Andric __construct_at_end(__n, false); 24780b57cec5SDimitry Andric } 24790b57cec5SDimitry Andric} 24800b57cec5SDimitry Andric 24810b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 24820b57cec5SDimitry Andrictemplate <class _Allocator> 24830b57cec5SDimitry Andricvector<bool, _Allocator>::vector(size_type __n, const allocator_type& __a) 24840b57cec5SDimitry Andric : __begin_(nullptr), 24850b57cec5SDimitry Andric __size_(0), 24860b57cec5SDimitry Andric __cap_alloc_(0, static_cast<__storage_allocator>(__a)) 24870b57cec5SDimitry Andric{ 24880b57cec5SDimitry Andric if (__n > 0) 24890b57cec5SDimitry Andric { 24900b57cec5SDimitry Andric __vallocate(__n); 24910b57cec5SDimitry Andric __construct_at_end(__n, false); 24920b57cec5SDimitry Andric } 24930b57cec5SDimitry Andric} 24940b57cec5SDimitry Andric#endif 24950b57cec5SDimitry Andric 24960b57cec5SDimitry Andrictemplate <class _Allocator> 24970b57cec5SDimitry Andricvector<bool, _Allocator>::vector(size_type __n, const value_type& __x) 24980b57cec5SDimitry Andric : __begin_(nullptr), 24990b57cec5SDimitry Andric __size_(0), 2500480093f4SDimitry Andric __cap_alloc_(0, __default_init_tag()) 25010b57cec5SDimitry Andric{ 25020b57cec5SDimitry Andric if (__n > 0) 25030b57cec5SDimitry Andric { 25040b57cec5SDimitry Andric __vallocate(__n); 25050b57cec5SDimitry Andric __construct_at_end(__n, __x); 25060b57cec5SDimitry Andric } 25070b57cec5SDimitry Andric} 25080b57cec5SDimitry Andric 25090b57cec5SDimitry Andrictemplate <class _Allocator> 25100b57cec5SDimitry Andricvector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a) 25110b57cec5SDimitry Andric : __begin_(nullptr), 25120b57cec5SDimitry Andric __size_(0), 25130b57cec5SDimitry Andric __cap_alloc_(0, static_cast<__storage_allocator>(__a)) 25140b57cec5SDimitry Andric{ 25150b57cec5SDimitry Andric if (__n > 0) 25160b57cec5SDimitry Andric { 25170b57cec5SDimitry Andric __vallocate(__n); 25180b57cec5SDimitry Andric __construct_at_end(__n, __x); 25190b57cec5SDimitry Andric } 25200b57cec5SDimitry Andric} 25210b57cec5SDimitry Andric 25220b57cec5SDimitry Andrictemplate <class _Allocator> 25230b57cec5SDimitry Andrictemplate <class _InputIterator> 25240b57cec5SDimitry Andricvector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, 2525480093f4SDimitry Andric typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value && 2526480093f4SDimitry Andric !__is_cpp17_forward_iterator<_InputIterator>::value>::type*) 25270b57cec5SDimitry Andric : __begin_(nullptr), 25280b57cec5SDimitry Andric __size_(0), 2529480093f4SDimitry Andric __cap_alloc_(0, __default_init_tag()) 25300b57cec5SDimitry Andric{ 25310b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 25320b57cec5SDimitry Andric try 25330b57cec5SDimitry Andric { 25340b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 25350b57cec5SDimitry Andric for (; __first != __last; ++__first) 25360b57cec5SDimitry Andric push_back(*__first); 25370b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 25380b57cec5SDimitry Andric } 25390b57cec5SDimitry Andric catch (...) 25400b57cec5SDimitry Andric { 25410b57cec5SDimitry Andric if (__begin_ != nullptr) 25420b57cec5SDimitry Andric __storage_traits::deallocate(__alloc(), __begin_, __cap()); 2543*81ad6265SDimitry Andric std::__debug_db_invalidate_all(this); 25440b57cec5SDimitry Andric throw; 25450b57cec5SDimitry Andric } 25460b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 25470b57cec5SDimitry Andric} 25480b57cec5SDimitry Andric 25490b57cec5SDimitry Andrictemplate <class _Allocator> 25500b57cec5SDimitry Andrictemplate <class _InputIterator> 25510b57cec5SDimitry Andricvector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, 2552480093f4SDimitry Andric typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value && 2553480093f4SDimitry Andric !__is_cpp17_forward_iterator<_InputIterator>::value>::type*) 25540b57cec5SDimitry Andric : __begin_(nullptr), 25550b57cec5SDimitry Andric __size_(0), 25560b57cec5SDimitry Andric __cap_alloc_(0, static_cast<__storage_allocator>(__a)) 25570b57cec5SDimitry Andric{ 25580b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 25590b57cec5SDimitry Andric try 25600b57cec5SDimitry Andric { 25610b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 25620b57cec5SDimitry Andric for (; __first != __last; ++__first) 25630b57cec5SDimitry Andric push_back(*__first); 25640b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 25650b57cec5SDimitry Andric } 25660b57cec5SDimitry Andric catch (...) 25670b57cec5SDimitry Andric { 25680b57cec5SDimitry Andric if (__begin_ != nullptr) 25690b57cec5SDimitry Andric __storage_traits::deallocate(__alloc(), __begin_, __cap()); 2570*81ad6265SDimitry Andric std::__debug_db_invalidate_all(this); 25710b57cec5SDimitry Andric throw; 25720b57cec5SDimitry Andric } 25730b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 25740b57cec5SDimitry Andric} 25750b57cec5SDimitry Andric 25760b57cec5SDimitry Andrictemplate <class _Allocator> 25770b57cec5SDimitry Andrictemplate <class _ForwardIterator> 25780b57cec5SDimitry Andricvector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, 2579480093f4SDimitry Andric typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type*) 25800b57cec5SDimitry Andric : __begin_(nullptr), 25810b57cec5SDimitry Andric __size_(0), 2582480093f4SDimitry Andric __cap_alloc_(0, __default_init_tag()) 25830b57cec5SDimitry Andric{ 25840b57cec5SDimitry Andric size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); 25850b57cec5SDimitry Andric if (__n > 0) 25860b57cec5SDimitry Andric { 25870b57cec5SDimitry Andric __vallocate(__n); 25880b57cec5SDimitry Andric __construct_at_end(__first, __last); 25890b57cec5SDimitry Andric } 25900b57cec5SDimitry Andric} 25910b57cec5SDimitry Andric 25920b57cec5SDimitry Andrictemplate <class _Allocator> 25930b57cec5SDimitry Andrictemplate <class _ForwardIterator> 25940b57cec5SDimitry Andricvector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, 2595480093f4SDimitry Andric typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type*) 25960b57cec5SDimitry Andric : __begin_(nullptr), 25970b57cec5SDimitry Andric __size_(0), 25980b57cec5SDimitry Andric __cap_alloc_(0, static_cast<__storage_allocator>(__a)) 25990b57cec5SDimitry Andric{ 26000b57cec5SDimitry Andric size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); 26010b57cec5SDimitry Andric if (__n > 0) 26020b57cec5SDimitry Andric { 26030b57cec5SDimitry Andric __vallocate(__n); 26040b57cec5SDimitry Andric __construct_at_end(__first, __last); 26050b57cec5SDimitry Andric } 26060b57cec5SDimitry Andric} 26070b57cec5SDimitry Andric 26080b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 26090b57cec5SDimitry Andric 26100b57cec5SDimitry Andrictemplate <class _Allocator> 26110b57cec5SDimitry Andricvector<bool, _Allocator>::vector(initializer_list<value_type> __il) 26120b57cec5SDimitry Andric : __begin_(nullptr), 26130b57cec5SDimitry Andric __size_(0), 2614480093f4SDimitry Andric __cap_alloc_(0, __default_init_tag()) 26150b57cec5SDimitry Andric{ 26160b57cec5SDimitry Andric size_type __n = static_cast<size_type>(__il.size()); 26170b57cec5SDimitry Andric if (__n > 0) 26180b57cec5SDimitry Andric { 26190b57cec5SDimitry Andric __vallocate(__n); 26200b57cec5SDimitry Andric __construct_at_end(__il.begin(), __il.end()); 26210b57cec5SDimitry Andric } 26220b57cec5SDimitry Andric} 26230b57cec5SDimitry Andric 26240b57cec5SDimitry Andrictemplate <class _Allocator> 26250b57cec5SDimitry Andricvector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a) 26260b57cec5SDimitry Andric : __begin_(nullptr), 26270b57cec5SDimitry Andric __size_(0), 26280b57cec5SDimitry Andric __cap_alloc_(0, static_cast<__storage_allocator>(__a)) 26290b57cec5SDimitry Andric{ 26300b57cec5SDimitry Andric size_type __n = static_cast<size_type>(__il.size()); 26310b57cec5SDimitry Andric if (__n > 0) 26320b57cec5SDimitry Andric { 26330b57cec5SDimitry Andric __vallocate(__n); 26340b57cec5SDimitry Andric __construct_at_end(__il.begin(), __il.end()); 26350b57cec5SDimitry Andric } 26360b57cec5SDimitry Andric} 26370b57cec5SDimitry Andric 26380b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 26390b57cec5SDimitry Andric 26400b57cec5SDimitry Andrictemplate <class _Allocator> 26410b57cec5SDimitry Andricvector<bool, _Allocator>::~vector() 26420b57cec5SDimitry Andric{ 26430b57cec5SDimitry Andric if (__begin_ != nullptr) 26440b57cec5SDimitry Andric __storage_traits::deallocate(__alloc(), __begin_, __cap()); 2645*81ad6265SDimitry Andric std::__debug_db_invalidate_all(this); 26460b57cec5SDimitry Andric} 26470b57cec5SDimitry Andric 26480b57cec5SDimitry Andrictemplate <class _Allocator> 26490b57cec5SDimitry Andricvector<bool, _Allocator>::vector(const vector& __v) 26500b57cec5SDimitry Andric : __begin_(nullptr), 26510b57cec5SDimitry Andric __size_(0), 26520b57cec5SDimitry Andric __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc())) 26530b57cec5SDimitry Andric{ 26540b57cec5SDimitry Andric if (__v.size() > 0) 26550b57cec5SDimitry Andric { 26560b57cec5SDimitry Andric __vallocate(__v.size()); 26570b57cec5SDimitry Andric __construct_at_end(__v.begin(), __v.end()); 26580b57cec5SDimitry Andric } 26590b57cec5SDimitry Andric} 26600b57cec5SDimitry Andric 26610b57cec5SDimitry Andrictemplate <class _Allocator> 26620b57cec5SDimitry Andricvector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a) 26630b57cec5SDimitry Andric : __begin_(nullptr), 26640b57cec5SDimitry Andric __size_(0), 26650b57cec5SDimitry Andric __cap_alloc_(0, __a) 26660b57cec5SDimitry Andric{ 26670b57cec5SDimitry Andric if (__v.size() > 0) 26680b57cec5SDimitry Andric { 26690b57cec5SDimitry Andric __vallocate(__v.size()); 26700b57cec5SDimitry Andric __construct_at_end(__v.begin(), __v.end()); 26710b57cec5SDimitry Andric } 26720b57cec5SDimitry Andric} 26730b57cec5SDimitry Andric 26740b57cec5SDimitry Andrictemplate <class _Allocator> 26750b57cec5SDimitry Andricvector<bool, _Allocator>& 26760b57cec5SDimitry Andricvector<bool, _Allocator>::operator=(const vector& __v) 26770b57cec5SDimitry Andric{ 2678349cc55cSDimitry Andric if (this != _VSTD::addressof(__v)) 26790b57cec5SDimitry Andric { 26800b57cec5SDimitry Andric __copy_assign_alloc(__v); 26810b57cec5SDimitry Andric if (__v.__size_) 26820b57cec5SDimitry Andric { 26830b57cec5SDimitry Andric if (__v.__size_ > capacity()) 26840b57cec5SDimitry Andric { 26850b57cec5SDimitry Andric __vdeallocate(); 26860b57cec5SDimitry Andric __vallocate(__v.__size_); 26870b57cec5SDimitry Andric } 26880b57cec5SDimitry Andric _VSTD::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_); 26890b57cec5SDimitry Andric } 26900b57cec5SDimitry Andric __size_ = __v.__size_; 26910b57cec5SDimitry Andric } 26920b57cec5SDimitry Andric return *this; 26930b57cec5SDimitry Andric} 26940b57cec5SDimitry Andric 26950b57cec5SDimitry Andrictemplate <class _Allocator> 26960b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY vector<bool, _Allocator>::vector(vector&& __v) 26970b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 26980b57cec5SDimitry Andric _NOEXCEPT 26990b57cec5SDimitry Andric#else 27000b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) 27010b57cec5SDimitry Andric#endif 27020b57cec5SDimitry Andric : __begin_(__v.__begin_), 27030b57cec5SDimitry Andric __size_(__v.__size_), 2704e8d8bef9SDimitry Andric __cap_alloc_(_VSTD::move(__v.__cap_alloc_)) { 27050b57cec5SDimitry Andric __v.__begin_ = nullptr; 27060b57cec5SDimitry Andric __v.__size_ = 0; 27070b57cec5SDimitry Andric __v.__cap() = 0; 27080b57cec5SDimitry Andric} 27090b57cec5SDimitry Andric 27100b57cec5SDimitry Andrictemplate <class _Allocator> 2711*81ad6265SDimitry Andricvector<bool, _Allocator>::vector(vector&& __v, const __type_identity_t<allocator_type>& __a) 27120b57cec5SDimitry Andric : __begin_(nullptr), 27130b57cec5SDimitry Andric __size_(0), 27140b57cec5SDimitry Andric __cap_alloc_(0, __a) 27150b57cec5SDimitry Andric{ 27160b57cec5SDimitry Andric if (__a == allocator_type(__v.__alloc())) 27170b57cec5SDimitry Andric { 27180b57cec5SDimitry Andric this->__begin_ = __v.__begin_; 27190b57cec5SDimitry Andric this->__size_ = __v.__size_; 27200b57cec5SDimitry Andric this->__cap() = __v.__cap(); 27210b57cec5SDimitry Andric __v.__begin_ = nullptr; 27220b57cec5SDimitry Andric __v.__cap() = __v.__size_ = 0; 27230b57cec5SDimitry Andric } 27240b57cec5SDimitry Andric else if (__v.size() > 0) 27250b57cec5SDimitry Andric { 27260b57cec5SDimitry Andric __vallocate(__v.size()); 27270b57cec5SDimitry Andric __construct_at_end(__v.begin(), __v.end()); 27280b57cec5SDimitry Andric } 27290b57cec5SDimitry Andric} 27300b57cec5SDimitry Andric 27310b57cec5SDimitry Andrictemplate <class _Allocator> 27320b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 27330b57cec5SDimitry Andricvector<bool, _Allocator>& 27340b57cec5SDimitry Andricvector<bool, _Allocator>::operator=(vector&& __v) 27350b57cec5SDimitry Andric _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) 27360b57cec5SDimitry Andric{ 27370b57cec5SDimitry Andric __move_assign(__v, integral_constant<bool, 27380b57cec5SDimitry Andric __storage_traits::propagate_on_container_move_assignment::value>()); 27390b57cec5SDimitry Andric return *this; 27400b57cec5SDimitry Andric} 27410b57cec5SDimitry Andric 27420b57cec5SDimitry Andrictemplate <class _Allocator> 27430b57cec5SDimitry Andricvoid 27440b57cec5SDimitry Andricvector<bool, _Allocator>::__move_assign(vector& __c, false_type) 27450b57cec5SDimitry Andric{ 27460b57cec5SDimitry Andric if (__alloc() != __c.__alloc()) 27470b57cec5SDimitry Andric assign(__c.begin(), __c.end()); 27480b57cec5SDimitry Andric else 27490b57cec5SDimitry Andric __move_assign(__c, true_type()); 27500b57cec5SDimitry Andric} 27510b57cec5SDimitry Andric 27520b57cec5SDimitry Andrictemplate <class _Allocator> 27530b57cec5SDimitry Andricvoid 27540b57cec5SDimitry Andricvector<bool, _Allocator>::__move_assign(vector& __c, true_type) 27550b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) 27560b57cec5SDimitry Andric{ 27570b57cec5SDimitry Andric __vdeallocate(); 27580b57cec5SDimitry Andric __move_assign_alloc(__c); 27590b57cec5SDimitry Andric this->__begin_ = __c.__begin_; 27600b57cec5SDimitry Andric this->__size_ = __c.__size_; 27610b57cec5SDimitry Andric this->__cap() = __c.__cap(); 27620b57cec5SDimitry Andric __c.__begin_ = nullptr; 27630b57cec5SDimitry Andric __c.__cap() = __c.__size_ = 0; 27640b57cec5SDimitry Andric} 27650b57cec5SDimitry Andric 27660b57cec5SDimitry Andrictemplate <class _Allocator> 27670b57cec5SDimitry Andricvoid 27680b57cec5SDimitry Andricvector<bool, _Allocator>::assign(size_type __n, const value_type& __x) 27690b57cec5SDimitry Andric{ 27700b57cec5SDimitry Andric __size_ = 0; 27710b57cec5SDimitry Andric if (__n > 0) 27720b57cec5SDimitry Andric { 27730b57cec5SDimitry Andric size_type __c = capacity(); 27740b57cec5SDimitry Andric if (__n <= __c) 27750b57cec5SDimitry Andric __size_ = __n; 27760b57cec5SDimitry Andric else 27770b57cec5SDimitry Andric { 2778349cc55cSDimitry Andric vector __v(get_allocator()); 27790b57cec5SDimitry Andric __v.reserve(__recommend(__n)); 27800b57cec5SDimitry Andric __v.__size_ = __n; 27810b57cec5SDimitry Andric swap(__v); 27820b57cec5SDimitry Andric } 27830b57cec5SDimitry Andric _VSTD::fill_n(begin(), __n, __x); 27840b57cec5SDimitry Andric } 2785*81ad6265SDimitry Andric std::__debug_db_invalidate_all(this); 27860b57cec5SDimitry Andric} 27870b57cec5SDimitry Andric 27880b57cec5SDimitry Andrictemplate <class _Allocator> 27890b57cec5SDimitry Andrictemplate <class _InputIterator> 27900b57cec5SDimitry Andrictypename enable_if 27910b57cec5SDimitry Andric< 2792480093f4SDimitry Andric __is_cpp17_input_iterator<_InputIterator>::value && 2793480093f4SDimitry Andric !__is_cpp17_forward_iterator<_InputIterator>::value, 27940b57cec5SDimitry Andric void 27950b57cec5SDimitry Andric>::type 27960b57cec5SDimitry Andricvector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last) 27970b57cec5SDimitry Andric{ 27980b57cec5SDimitry Andric clear(); 27990b57cec5SDimitry Andric for (; __first != __last; ++__first) 28000b57cec5SDimitry Andric push_back(*__first); 28010b57cec5SDimitry Andric} 28020b57cec5SDimitry Andric 28030b57cec5SDimitry Andrictemplate <class _Allocator> 28040b57cec5SDimitry Andrictemplate <class _ForwardIterator> 28050b57cec5SDimitry Andrictypename enable_if 28060b57cec5SDimitry Andric< 2807480093f4SDimitry Andric __is_cpp17_forward_iterator<_ForwardIterator>::value, 28080b57cec5SDimitry Andric void 28090b57cec5SDimitry Andric>::type 28100b57cec5SDimitry Andricvector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) 28110b57cec5SDimitry Andric{ 28120b57cec5SDimitry Andric clear(); 28130b57cec5SDimitry Andric difference_type __ns = _VSTD::distance(__first, __last); 28140b57cec5SDimitry Andric _LIBCPP_ASSERT(__ns >= 0, "invalid range specified"); 28150b57cec5SDimitry Andric const size_t __n = static_cast<size_type>(__ns); 28160b57cec5SDimitry Andric if (__n) 28170b57cec5SDimitry Andric { 28180b57cec5SDimitry Andric if (__n > capacity()) 28190b57cec5SDimitry Andric { 28200b57cec5SDimitry Andric __vdeallocate(); 28210b57cec5SDimitry Andric __vallocate(__n); 28220b57cec5SDimitry Andric } 28230b57cec5SDimitry Andric __construct_at_end(__first, __last); 28240b57cec5SDimitry Andric } 28250b57cec5SDimitry Andric} 28260b57cec5SDimitry Andric 28270b57cec5SDimitry Andrictemplate <class _Allocator> 28280b57cec5SDimitry Andricvoid 28290b57cec5SDimitry Andricvector<bool, _Allocator>::reserve(size_type __n) 28300b57cec5SDimitry Andric{ 28310b57cec5SDimitry Andric if (__n > capacity()) 28320b57cec5SDimitry Andric { 2833349cc55cSDimitry Andric if (__n > max_size()) 2834349cc55cSDimitry Andric this->__throw_length_error(); 2835349cc55cSDimitry Andric vector __v(this->get_allocator()); 28360b57cec5SDimitry Andric __v.__vallocate(__n); 28370b57cec5SDimitry Andric __v.__construct_at_end(this->begin(), this->end()); 28380b57cec5SDimitry Andric swap(__v); 2839*81ad6265SDimitry Andric std::__debug_db_invalidate_all(this); 28400b57cec5SDimitry Andric } 28410b57cec5SDimitry Andric} 28420b57cec5SDimitry Andric 28430b57cec5SDimitry Andrictemplate <class _Allocator> 28440b57cec5SDimitry Andricvoid 28450b57cec5SDimitry Andricvector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT 28460b57cec5SDimitry Andric{ 28470b57cec5SDimitry Andric if (__external_cap_to_internal(size()) > __cap()) 28480b57cec5SDimitry Andric { 28490b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 28500b57cec5SDimitry Andric try 28510b57cec5SDimitry Andric { 28520b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 28530b57cec5SDimitry Andric vector(*this, allocator_type(__alloc())).swap(*this); 28540b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 28550b57cec5SDimitry Andric } 28560b57cec5SDimitry Andric catch (...) 28570b57cec5SDimitry Andric { 28580b57cec5SDimitry Andric } 28590b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 28600b57cec5SDimitry Andric } 28610b57cec5SDimitry Andric} 28620b57cec5SDimitry Andric 28630b57cec5SDimitry Andrictemplate <class _Allocator> 28640b57cec5SDimitry Andrictypename vector<bool, _Allocator>::reference 28650b57cec5SDimitry Andricvector<bool, _Allocator>::at(size_type __n) 28660b57cec5SDimitry Andric{ 28670b57cec5SDimitry Andric if (__n >= size()) 28680b57cec5SDimitry Andric this->__throw_out_of_range(); 28690b57cec5SDimitry Andric return (*this)[__n]; 28700b57cec5SDimitry Andric} 28710b57cec5SDimitry Andric 28720b57cec5SDimitry Andrictemplate <class _Allocator> 28730b57cec5SDimitry Andrictypename vector<bool, _Allocator>::const_reference 28740b57cec5SDimitry Andricvector<bool, _Allocator>::at(size_type __n) const 28750b57cec5SDimitry Andric{ 28760b57cec5SDimitry Andric if (__n >= size()) 28770b57cec5SDimitry Andric this->__throw_out_of_range(); 28780b57cec5SDimitry Andric return (*this)[__n]; 28790b57cec5SDimitry Andric} 28800b57cec5SDimitry Andric 28810b57cec5SDimitry Andrictemplate <class _Allocator> 28820b57cec5SDimitry Andricvoid 28830b57cec5SDimitry Andricvector<bool, _Allocator>::push_back(const value_type& __x) 28840b57cec5SDimitry Andric{ 28850b57cec5SDimitry Andric if (this->__size_ == this->capacity()) 28860b57cec5SDimitry Andric reserve(__recommend(this->__size_ + 1)); 28870b57cec5SDimitry Andric ++this->__size_; 28880b57cec5SDimitry Andric back() = __x; 28890b57cec5SDimitry Andric} 28900b57cec5SDimitry Andric 28910b57cec5SDimitry Andrictemplate <class _Allocator> 28920b57cec5SDimitry Andrictypename vector<bool, _Allocator>::iterator 28930b57cec5SDimitry Andricvector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x) 28940b57cec5SDimitry Andric{ 28950b57cec5SDimitry Andric iterator __r; 28960b57cec5SDimitry Andric if (size() < capacity()) 28970b57cec5SDimitry Andric { 28980b57cec5SDimitry Andric const_iterator __old_end = end(); 28990b57cec5SDimitry Andric ++__size_; 29000b57cec5SDimitry Andric _VSTD::copy_backward(__position, __old_end, end()); 29010b57cec5SDimitry Andric __r = __const_iterator_cast(__position); 29020b57cec5SDimitry Andric } 29030b57cec5SDimitry Andric else 29040b57cec5SDimitry Andric { 2905349cc55cSDimitry Andric vector __v(get_allocator()); 29060b57cec5SDimitry Andric __v.reserve(__recommend(__size_ + 1)); 29070b57cec5SDimitry Andric __v.__size_ = __size_ + 1; 29080b57cec5SDimitry Andric __r = _VSTD::copy(cbegin(), __position, __v.begin()); 29090b57cec5SDimitry Andric _VSTD::copy_backward(__position, cend(), __v.end()); 29100b57cec5SDimitry Andric swap(__v); 29110b57cec5SDimitry Andric } 29120b57cec5SDimitry Andric *__r = __x; 29130b57cec5SDimitry Andric return __r; 29140b57cec5SDimitry Andric} 29150b57cec5SDimitry Andric 29160b57cec5SDimitry Andrictemplate <class _Allocator> 29170b57cec5SDimitry Andrictypename vector<bool, _Allocator>::iterator 29180b57cec5SDimitry Andricvector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x) 29190b57cec5SDimitry Andric{ 29200b57cec5SDimitry Andric iterator __r; 29210b57cec5SDimitry Andric size_type __c = capacity(); 29220b57cec5SDimitry Andric if (__n <= __c && size() <= __c - __n) 29230b57cec5SDimitry Andric { 29240b57cec5SDimitry Andric const_iterator __old_end = end(); 29250b57cec5SDimitry Andric __size_ += __n; 29260b57cec5SDimitry Andric _VSTD::copy_backward(__position, __old_end, end()); 29270b57cec5SDimitry Andric __r = __const_iterator_cast(__position); 29280b57cec5SDimitry Andric } 29290b57cec5SDimitry Andric else 29300b57cec5SDimitry Andric { 2931349cc55cSDimitry Andric vector __v(get_allocator()); 29320b57cec5SDimitry Andric __v.reserve(__recommend(__size_ + __n)); 29330b57cec5SDimitry Andric __v.__size_ = __size_ + __n; 29340b57cec5SDimitry Andric __r = _VSTD::copy(cbegin(), __position, __v.begin()); 29350b57cec5SDimitry Andric _VSTD::copy_backward(__position, cend(), __v.end()); 29360b57cec5SDimitry Andric swap(__v); 29370b57cec5SDimitry Andric } 29380b57cec5SDimitry Andric _VSTD::fill_n(__r, __n, __x); 29390b57cec5SDimitry Andric return __r; 29400b57cec5SDimitry Andric} 29410b57cec5SDimitry Andric 29420b57cec5SDimitry Andrictemplate <class _Allocator> 29430b57cec5SDimitry Andrictemplate <class _InputIterator> 29440b57cec5SDimitry Andrictypename enable_if 29450b57cec5SDimitry Andric< 2946480093f4SDimitry Andric __is_cpp17_input_iterator <_InputIterator>::value && 2947480093f4SDimitry Andric !__is_cpp17_forward_iterator<_InputIterator>::value, 29480b57cec5SDimitry Andric typename vector<bool, _Allocator>::iterator 29490b57cec5SDimitry Andric>::type 29500b57cec5SDimitry Andricvector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last) 29510b57cec5SDimitry Andric{ 29520b57cec5SDimitry Andric difference_type __off = __position - begin(); 29530b57cec5SDimitry Andric iterator __p = __const_iterator_cast(__position); 29540b57cec5SDimitry Andric iterator __old_end = end(); 29550b57cec5SDimitry Andric for (; size() != capacity() && __first != __last; ++__first) 29560b57cec5SDimitry Andric { 29570b57cec5SDimitry Andric ++this->__size_; 29580b57cec5SDimitry Andric back() = *__first; 29590b57cec5SDimitry Andric } 2960349cc55cSDimitry Andric vector __v(get_allocator()); 29610b57cec5SDimitry Andric if (__first != __last) 29620b57cec5SDimitry Andric { 29630b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 29640b57cec5SDimitry Andric try 29650b57cec5SDimitry Andric { 29660b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 29670b57cec5SDimitry Andric __v.assign(__first, __last); 29680b57cec5SDimitry Andric difference_type __old_size = static_cast<difference_type>(__old_end - begin()); 29690b57cec5SDimitry Andric difference_type __old_p = __p - begin(); 29700b57cec5SDimitry Andric reserve(__recommend(size() + __v.size())); 29710b57cec5SDimitry Andric __p = begin() + __old_p; 29720b57cec5SDimitry Andric __old_end = begin() + __old_size; 29730b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 29740b57cec5SDimitry Andric } 29750b57cec5SDimitry Andric catch (...) 29760b57cec5SDimitry Andric { 29770b57cec5SDimitry Andric erase(__old_end, end()); 29780b57cec5SDimitry Andric throw; 29790b57cec5SDimitry Andric } 29800b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 29810b57cec5SDimitry Andric } 29820b57cec5SDimitry Andric __p = _VSTD::rotate(__p, __old_end, end()); 29830b57cec5SDimitry Andric insert(__p, __v.begin(), __v.end()); 29840b57cec5SDimitry Andric return begin() + __off; 29850b57cec5SDimitry Andric} 29860b57cec5SDimitry Andric 29870b57cec5SDimitry Andrictemplate <class _Allocator> 29880b57cec5SDimitry Andrictemplate <class _ForwardIterator> 29890b57cec5SDimitry Andrictypename enable_if 29900b57cec5SDimitry Andric< 2991480093f4SDimitry Andric __is_cpp17_forward_iterator<_ForwardIterator>::value, 29920b57cec5SDimitry Andric typename vector<bool, _Allocator>::iterator 29930b57cec5SDimitry Andric>::type 29940b57cec5SDimitry Andricvector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last) 29950b57cec5SDimitry Andric{ 29960b57cec5SDimitry Andric const difference_type __n_signed = _VSTD::distance(__first, __last); 29970b57cec5SDimitry Andric _LIBCPP_ASSERT(__n_signed >= 0, "invalid range specified"); 29980b57cec5SDimitry Andric const size_type __n = static_cast<size_type>(__n_signed); 29990b57cec5SDimitry Andric iterator __r; 30000b57cec5SDimitry Andric size_type __c = capacity(); 30010b57cec5SDimitry Andric if (__n <= __c && size() <= __c - __n) 30020b57cec5SDimitry Andric { 30030b57cec5SDimitry Andric const_iterator __old_end = end(); 30040b57cec5SDimitry Andric __size_ += __n; 30050b57cec5SDimitry Andric _VSTD::copy_backward(__position, __old_end, end()); 30060b57cec5SDimitry Andric __r = __const_iterator_cast(__position); 30070b57cec5SDimitry Andric } 30080b57cec5SDimitry Andric else 30090b57cec5SDimitry Andric { 3010349cc55cSDimitry Andric vector __v(get_allocator()); 30110b57cec5SDimitry Andric __v.reserve(__recommend(__size_ + __n)); 30120b57cec5SDimitry Andric __v.__size_ = __size_ + __n; 30130b57cec5SDimitry Andric __r = _VSTD::copy(cbegin(), __position, __v.begin()); 30140b57cec5SDimitry Andric _VSTD::copy_backward(__position, cend(), __v.end()); 30150b57cec5SDimitry Andric swap(__v); 30160b57cec5SDimitry Andric } 30170b57cec5SDimitry Andric _VSTD::copy(__first, __last, __r); 30180b57cec5SDimitry Andric return __r; 30190b57cec5SDimitry Andric} 30200b57cec5SDimitry Andric 30210b57cec5SDimitry Andrictemplate <class _Allocator> 30220b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 30230b57cec5SDimitry Andrictypename vector<bool, _Allocator>::iterator 30240b57cec5SDimitry Andricvector<bool, _Allocator>::erase(const_iterator __position) 30250b57cec5SDimitry Andric{ 30260b57cec5SDimitry Andric iterator __r = __const_iterator_cast(__position); 30270b57cec5SDimitry Andric _VSTD::copy(__position + 1, this->cend(), __r); 30280b57cec5SDimitry Andric --__size_; 30290b57cec5SDimitry Andric return __r; 30300b57cec5SDimitry Andric} 30310b57cec5SDimitry Andric 30320b57cec5SDimitry Andrictemplate <class _Allocator> 30330b57cec5SDimitry Andrictypename vector<bool, _Allocator>::iterator 30340b57cec5SDimitry Andricvector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last) 30350b57cec5SDimitry Andric{ 30360b57cec5SDimitry Andric iterator __r = __const_iterator_cast(__first); 30370b57cec5SDimitry Andric difference_type __d = __last - __first; 30380b57cec5SDimitry Andric _VSTD::copy(__last, this->cend(), __r); 30390b57cec5SDimitry Andric __size_ -= __d; 30400b57cec5SDimitry Andric return __r; 30410b57cec5SDimitry Andric} 30420b57cec5SDimitry Andric 30430b57cec5SDimitry Andrictemplate <class _Allocator> 30440b57cec5SDimitry Andricvoid 30450b57cec5SDimitry Andricvector<bool, _Allocator>::swap(vector& __x) 30460b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14 30470b57cec5SDimitry Andric _NOEXCEPT 30480b57cec5SDimitry Andric#else 30490b57cec5SDimitry Andric _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || 30500b57cec5SDimitry Andric __is_nothrow_swappable<allocator_type>::value) 30510b57cec5SDimitry Andric#endif 30520b57cec5SDimitry Andric{ 30530b57cec5SDimitry Andric _VSTD::swap(this->__begin_, __x.__begin_); 30540b57cec5SDimitry Andric _VSTD::swap(this->__size_, __x.__size_); 30550b57cec5SDimitry Andric _VSTD::swap(this->__cap(), __x.__cap()); 3056e8d8bef9SDimitry Andric _VSTD::__swap_allocator(this->__alloc(), __x.__alloc(), 30570b57cec5SDimitry Andric integral_constant<bool, __alloc_traits::propagate_on_container_swap::value>()); 30580b57cec5SDimitry Andric} 30590b57cec5SDimitry Andric 30600b57cec5SDimitry Andrictemplate <class _Allocator> 30610b57cec5SDimitry Andricvoid 30620b57cec5SDimitry Andricvector<bool, _Allocator>::resize(size_type __sz, value_type __x) 30630b57cec5SDimitry Andric{ 30640b57cec5SDimitry Andric size_type __cs = size(); 30650b57cec5SDimitry Andric if (__cs < __sz) 30660b57cec5SDimitry Andric { 30670b57cec5SDimitry Andric iterator __r; 30680b57cec5SDimitry Andric size_type __c = capacity(); 30690b57cec5SDimitry Andric size_type __n = __sz - __cs; 30700b57cec5SDimitry Andric if (__n <= __c && __cs <= __c - __n) 30710b57cec5SDimitry Andric { 30720b57cec5SDimitry Andric __r = end(); 30730b57cec5SDimitry Andric __size_ += __n; 30740b57cec5SDimitry Andric } 30750b57cec5SDimitry Andric else 30760b57cec5SDimitry Andric { 3077349cc55cSDimitry Andric vector __v(get_allocator()); 30780b57cec5SDimitry Andric __v.reserve(__recommend(__size_ + __n)); 30790b57cec5SDimitry Andric __v.__size_ = __size_ + __n; 30800b57cec5SDimitry Andric __r = _VSTD::copy(cbegin(), cend(), __v.begin()); 30810b57cec5SDimitry Andric swap(__v); 30820b57cec5SDimitry Andric } 30830b57cec5SDimitry Andric _VSTD::fill_n(__r, __n, __x); 30840b57cec5SDimitry Andric } 30850b57cec5SDimitry Andric else 30860b57cec5SDimitry Andric __size_ = __sz; 30870b57cec5SDimitry Andric} 30880b57cec5SDimitry Andric 30890b57cec5SDimitry Andrictemplate <class _Allocator> 30900b57cec5SDimitry Andricvoid 30910b57cec5SDimitry Andricvector<bool, _Allocator>::flip() _NOEXCEPT 30920b57cec5SDimitry Andric{ 30930b57cec5SDimitry Andric // do middle whole words 30940b57cec5SDimitry Andric size_type __n = __size_; 30950b57cec5SDimitry Andric __storage_pointer __p = __begin_; 30960b57cec5SDimitry Andric for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) 30970b57cec5SDimitry Andric *__p = ~*__p; 30980b57cec5SDimitry Andric // do last partial word 30990b57cec5SDimitry Andric if (__n > 0) 31000b57cec5SDimitry Andric { 31010b57cec5SDimitry Andric __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); 31020b57cec5SDimitry Andric __storage_type __b = *__p & __m; 31030b57cec5SDimitry Andric *__p &= ~__m; 31040b57cec5SDimitry Andric *__p |= ~__b & __m; 31050b57cec5SDimitry Andric } 31060b57cec5SDimitry Andric} 31070b57cec5SDimitry Andric 31080b57cec5SDimitry Andrictemplate <class _Allocator> 31090b57cec5SDimitry Andricbool 31100b57cec5SDimitry Andricvector<bool, _Allocator>::__invariants() const 31110b57cec5SDimitry Andric{ 31120b57cec5SDimitry Andric if (this->__begin_ == nullptr) 31130b57cec5SDimitry Andric { 31140b57cec5SDimitry Andric if (this->__size_ != 0 || this->__cap() != 0) 31150b57cec5SDimitry Andric return false; 31160b57cec5SDimitry Andric } 31170b57cec5SDimitry Andric else 31180b57cec5SDimitry Andric { 31190b57cec5SDimitry Andric if (this->__cap() == 0) 31200b57cec5SDimitry Andric return false; 31210b57cec5SDimitry Andric if (this->__size_ > this->capacity()) 31220b57cec5SDimitry Andric return false; 31230b57cec5SDimitry Andric } 31240b57cec5SDimitry Andric return true; 31250b57cec5SDimitry Andric} 31260b57cec5SDimitry Andric 31270b57cec5SDimitry Andrictemplate <class _Allocator> 31280b57cec5SDimitry Andricsize_t 31290b57cec5SDimitry Andricvector<bool, _Allocator>::__hash_code() const _NOEXCEPT 31300b57cec5SDimitry Andric{ 31310b57cec5SDimitry Andric size_t __h = 0; 31320b57cec5SDimitry Andric // do middle whole words 31330b57cec5SDimitry Andric size_type __n = __size_; 31340b57cec5SDimitry Andric __storage_pointer __p = __begin_; 31350b57cec5SDimitry Andric for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) 31360b57cec5SDimitry Andric __h ^= *__p; 31370b57cec5SDimitry Andric // do last partial word 31380b57cec5SDimitry Andric if (__n > 0) 31390b57cec5SDimitry Andric { 31400b57cec5SDimitry Andric const __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); 31410b57cec5SDimitry Andric __h ^= *__p & __m; 31420b57cec5SDimitry Andric } 31430b57cec5SDimitry Andric return __h; 31440b57cec5SDimitry Andric} 31450b57cec5SDimitry Andric 31460b57cec5SDimitry Andrictemplate <class _Allocator> 31470b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<vector<bool, _Allocator> > 3148*81ad6265SDimitry Andric : public __unary_function<vector<bool, _Allocator>, size_t> 31490b57cec5SDimitry Andric{ 31500b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 31510b57cec5SDimitry Andric size_t operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT 31520b57cec5SDimitry Andric {return __vec.__hash_code();} 31530b57cec5SDimitry Andric}; 31540b57cec5SDimitry Andric 31550b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 31560b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 31570b57cec5SDimitry Andricbool 31580b57cec5SDimitry Andricoperator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) 31590b57cec5SDimitry Andric{ 31600b57cec5SDimitry Andric const typename vector<_Tp, _Allocator>::size_type __sz = __x.size(); 31610b57cec5SDimitry Andric return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin()); 31620b57cec5SDimitry Andric} 31630b57cec5SDimitry Andric 31640b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 31650b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 31660b57cec5SDimitry Andricbool 31670b57cec5SDimitry Andricoperator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) 31680b57cec5SDimitry Andric{ 31690b57cec5SDimitry Andric return !(__x == __y); 31700b57cec5SDimitry Andric} 31710b57cec5SDimitry Andric 31720b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 31730b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 31740b57cec5SDimitry Andricbool 31750b57cec5SDimitry Andricoperator< (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) 31760b57cec5SDimitry Andric{ 31770b57cec5SDimitry Andric return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); 31780b57cec5SDimitry Andric} 31790b57cec5SDimitry Andric 31800b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 31810b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 31820b57cec5SDimitry Andricbool 31830b57cec5SDimitry Andricoperator> (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) 31840b57cec5SDimitry Andric{ 31850b57cec5SDimitry Andric return __y < __x; 31860b57cec5SDimitry Andric} 31870b57cec5SDimitry Andric 31880b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 31890b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 31900b57cec5SDimitry Andricbool 31910b57cec5SDimitry Andricoperator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) 31920b57cec5SDimitry Andric{ 31930b57cec5SDimitry Andric return !(__x < __y); 31940b57cec5SDimitry Andric} 31950b57cec5SDimitry Andric 31960b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 31970b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 31980b57cec5SDimitry Andricbool 31990b57cec5SDimitry Andricoperator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) 32000b57cec5SDimitry Andric{ 32010b57cec5SDimitry Andric return !(__y < __x); 32020b57cec5SDimitry Andric} 32030b57cec5SDimitry Andric 32040b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 32050b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 32060b57cec5SDimitry Andricvoid 32070b57cec5SDimitry Andricswap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y) 32080b57cec5SDimitry Andric _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) 32090b57cec5SDimitry Andric{ 32100b57cec5SDimitry Andric __x.swap(__y); 32110b57cec5SDimitry Andric} 32120b57cec5SDimitry Andric 32130b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 17 32140b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator, class _Up> 32155ffd83dbSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY typename vector<_Tp, _Allocator>::size_type 32165ffd83dbSDimitry Andricerase(vector<_Tp, _Allocator>& __c, const _Up& __v) { 32175ffd83dbSDimitry Andric auto __old_size = __c.size(); 32185ffd83dbSDimitry Andric __c.erase(_VSTD::remove(__c.begin(), __c.end(), __v), __c.end()); 32195ffd83dbSDimitry Andric return __old_size - __c.size(); 32205ffd83dbSDimitry Andric} 32210b57cec5SDimitry Andric 32220b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator, class _Predicate> 32235ffd83dbSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY typename vector<_Tp, _Allocator>::size_type 32245ffd83dbSDimitry Andricerase_if(vector<_Tp, _Allocator>& __c, _Predicate __pred) { 32255ffd83dbSDimitry Andric auto __old_size = __c.size(); 32265ffd83dbSDimitry Andric __c.erase(_VSTD::remove_if(__c.begin(), __c.end(), __pred), __c.end()); 32275ffd83dbSDimitry Andric return __old_size - __c.size(); 32285ffd83dbSDimitry Andric} 3229*81ad6265SDimitry Andric 3230*81ad6265SDimitry Andrictemplate <> 3231*81ad6265SDimitry Andricinline constexpr bool __format::__enable_insertable<std::vector<char>> = true; 3232*81ad6265SDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS 3233*81ad6265SDimitry Andrictemplate <> 3234*81ad6265SDimitry Andricinline constexpr bool __format::__enable_insertable<std::vector<wchar_t>> = true; 32350b57cec5SDimitry Andric#endif 32360b57cec5SDimitry Andric 3237*81ad6265SDimitry Andric#endif // _LIBCPP_STD_VER > 17 3238*81ad6265SDimitry Andric 32390b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD 32400b57cec5SDimitry Andric 32410b57cec5SDimitry Andric_LIBCPP_POP_MACROS 32420b57cec5SDimitry Andric 32430b57cec5SDimitry Andric#endif // _LIBCPP_VECTOR 3244