17a984708SDavid Chisnall// -*- C++ -*- 27a984708SDavid Chisnall//===------------------------------ vector --------------------------------===// 37a984708SDavid Chisnall// 47a984708SDavid Chisnall// The LLVM Compiler Infrastructure 57a984708SDavid Chisnall// 67a984708SDavid Chisnall// This file is dual licensed under the MIT and the University of Illinois Open 77a984708SDavid Chisnall// Source Licenses. See LICENSE.TXT for details. 87a984708SDavid Chisnall// 97a984708SDavid Chisnall//===----------------------------------------------------------------------===// 107a984708SDavid Chisnall 117a984708SDavid Chisnall#ifndef _LIBCPP_VECTOR 127a984708SDavid Chisnall#define _LIBCPP_VECTOR 137a984708SDavid Chisnall 147a984708SDavid Chisnall/* 157a984708SDavid Chisnall vector synopsis 167a984708SDavid Chisnall 177a984708SDavid Chisnallnamespace std 187a984708SDavid Chisnall{ 197a984708SDavid Chisnall 207a984708SDavid Chisnalltemplate <class T, class Allocator = allocator<T> > 217a984708SDavid Chisnallclass vector 227a984708SDavid Chisnall{ 237a984708SDavid Chisnallpublic: 247a984708SDavid Chisnall typedef T value_type; 257a984708SDavid Chisnall typedef Allocator allocator_type; 267a984708SDavid Chisnall typedef typename allocator_type::reference reference; 277a984708SDavid Chisnall typedef typename allocator_type::const_reference const_reference; 287a984708SDavid Chisnall typedef implementation-defined iterator; 297a984708SDavid Chisnall typedef implementation-defined const_iterator; 307a984708SDavid Chisnall typedef typename allocator_type::size_type size_type; 317a984708SDavid Chisnall typedef typename allocator_type::difference_type difference_type; 327a984708SDavid Chisnall typedef typename allocator_type::pointer pointer; 337a984708SDavid Chisnall typedef typename allocator_type::const_pointer const_pointer; 347a984708SDavid Chisnall typedef std::reverse_iterator<iterator> reverse_iterator; 357a984708SDavid Chisnall typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 367a984708SDavid Chisnall 377a984708SDavid Chisnall vector() 387a984708SDavid Chisnall noexcept(is_nothrow_default_constructible<allocator_type>::value); 397a984708SDavid Chisnall explicit vector(const allocator_type&); 407a984708SDavid Chisnall explicit vector(size_type n); 414f7ab58eSDimitry Andric explicit vector(size_type n, const allocator_type&); // C++14 427a984708SDavid Chisnall vector(size_type n, const value_type& value, const allocator_type& = allocator_type()); 437a984708SDavid Chisnall template <class InputIterator> 447a984708SDavid Chisnall vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type()); 457a984708SDavid Chisnall vector(const vector& x); 467a984708SDavid Chisnall vector(vector&& x) 477a984708SDavid Chisnall noexcept(is_nothrow_move_constructible<allocator_type>::value); 487a984708SDavid Chisnall vector(initializer_list<value_type> il); 497a984708SDavid Chisnall vector(initializer_list<value_type> il, const allocator_type& a); 507a984708SDavid Chisnall ~vector(); 517a984708SDavid Chisnall vector& operator=(const vector& x); 527a984708SDavid Chisnall vector& operator=(vector&& x) 537a984708SDavid Chisnall noexcept( 549729cf09SDimitry Andric allocator_type::propagate_on_container_move_assignment::value || 559729cf09SDimitry Andric allocator_type::is_always_equal::value); // C++17 567a984708SDavid Chisnall vector& operator=(initializer_list<value_type> il); 577a984708SDavid Chisnall template <class InputIterator> 587a984708SDavid Chisnall void assign(InputIterator first, InputIterator last); 597a984708SDavid Chisnall void assign(size_type n, const value_type& u); 607a984708SDavid Chisnall void assign(initializer_list<value_type> il); 617a984708SDavid Chisnall 627a984708SDavid Chisnall allocator_type get_allocator() const noexcept; 637a984708SDavid Chisnall 647a984708SDavid Chisnall iterator begin() noexcept; 657a984708SDavid Chisnall const_iterator begin() const noexcept; 667a984708SDavid Chisnall iterator end() noexcept; 677a984708SDavid Chisnall const_iterator end() const noexcept; 687a984708SDavid Chisnall 697a984708SDavid Chisnall reverse_iterator rbegin() noexcept; 707a984708SDavid Chisnall const_reverse_iterator rbegin() const noexcept; 717a984708SDavid Chisnall reverse_iterator rend() noexcept; 727a984708SDavid Chisnall const_reverse_iterator rend() const noexcept; 737a984708SDavid Chisnall 747a984708SDavid Chisnall const_iterator cbegin() const noexcept; 757a984708SDavid Chisnall const_iterator cend() const noexcept; 767a984708SDavid Chisnall const_reverse_iterator crbegin() const noexcept; 777a984708SDavid Chisnall const_reverse_iterator crend() const noexcept; 787a984708SDavid Chisnall 797a984708SDavid Chisnall size_type size() const noexcept; 807a984708SDavid Chisnall size_type max_size() const noexcept; 817a984708SDavid Chisnall size_type capacity() const noexcept; 827a984708SDavid Chisnall bool empty() const noexcept; 837a984708SDavid Chisnall void reserve(size_type n); 847a984708SDavid Chisnall void shrink_to_fit() noexcept; 857a984708SDavid Chisnall 867a984708SDavid Chisnall reference operator[](size_type n); 877a984708SDavid Chisnall const_reference operator[](size_type n) const; 887a984708SDavid Chisnall reference at(size_type n); 897a984708SDavid Chisnall const_reference at(size_type n) const; 907a984708SDavid Chisnall 917a984708SDavid Chisnall reference front(); 927a984708SDavid Chisnall const_reference front() const; 937a984708SDavid Chisnall reference back(); 947a984708SDavid Chisnall const_reference back() const; 957a984708SDavid Chisnall 967a984708SDavid Chisnall value_type* data() noexcept; 977a984708SDavid Chisnall const value_type* data() const noexcept; 987a984708SDavid Chisnall 997a984708SDavid Chisnall void push_back(const value_type& x); 1007a984708SDavid Chisnall void push_back(value_type&& x); 1017a984708SDavid Chisnall template <class... Args> 10298221d2eSDimitry Andric reference emplace_back(Args&&... args); // reference in C++17 1037a984708SDavid Chisnall void pop_back(); 1047a984708SDavid Chisnall 1057a984708SDavid Chisnall template <class... Args> iterator emplace(const_iterator position, Args&&... args); 1067a984708SDavid Chisnall iterator insert(const_iterator position, const value_type& x); 1077a984708SDavid Chisnall iterator insert(const_iterator position, value_type&& x); 1087a984708SDavid Chisnall iterator insert(const_iterator position, size_type n, const value_type& x); 1097a984708SDavid Chisnall template <class InputIterator> 1107a984708SDavid Chisnall iterator insert(const_iterator position, InputIterator first, InputIterator last); 1117a984708SDavid Chisnall iterator insert(const_iterator position, initializer_list<value_type> il); 1127a984708SDavid Chisnall 1137a984708SDavid Chisnall iterator erase(const_iterator position); 1147a984708SDavid Chisnall iterator erase(const_iterator first, const_iterator last); 1157a984708SDavid Chisnall 1167a984708SDavid Chisnall void clear() noexcept; 1177a984708SDavid Chisnall 1187a984708SDavid Chisnall void resize(size_type sz); 1197a984708SDavid Chisnall void resize(size_type sz, const value_type& c); 1207a984708SDavid Chisnall 1217a984708SDavid Chisnall void swap(vector&) 122854fa44bSDimitry Andric noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value || 123854fa44bSDimitry Andric allocator_traits<allocator_type>::is_always_equal::value); // C++17 1247a984708SDavid Chisnall 1257a984708SDavid Chisnall bool __invariants() const; 1267a984708SDavid Chisnall}; 1277a984708SDavid Chisnall 1287a984708SDavid Chisnalltemplate <class Allocator = allocator<T> > 1297a984708SDavid Chisnallclass vector<bool, Allocator> 1307a984708SDavid Chisnall{ 1317a984708SDavid Chisnallpublic: 1327a984708SDavid Chisnall typedef bool value_type; 1337a984708SDavid Chisnall typedef Allocator allocator_type; 1347a984708SDavid Chisnall typedef implementation-defined iterator; 1357a984708SDavid Chisnall typedef implementation-defined const_iterator; 1367a984708SDavid Chisnall typedef typename allocator_type::size_type size_type; 1377a984708SDavid Chisnall typedef typename allocator_type::difference_type difference_type; 1387a984708SDavid Chisnall typedef iterator pointer; 1397a984708SDavid Chisnall typedef const_iterator const_pointer; 1407a984708SDavid Chisnall typedef std::reverse_iterator<iterator> reverse_iterator; 1417a984708SDavid Chisnall typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 1427a984708SDavid Chisnall 1437a984708SDavid Chisnall class reference 1447a984708SDavid Chisnall { 1457a984708SDavid Chisnall public: 1467a984708SDavid Chisnall reference(const reference&) noexcept; 1477a984708SDavid Chisnall operator bool() const noexcept; 1487a984708SDavid Chisnall reference& operator=(const bool x) noexcept; 1497a984708SDavid Chisnall reference& operator=(const reference& x) noexcept; 1507a984708SDavid Chisnall iterator operator&() const noexcept; 1517a984708SDavid Chisnall void flip() noexcept; 1527a984708SDavid Chisnall }; 1537a984708SDavid Chisnall 1547a984708SDavid Chisnall class const_reference 1557a984708SDavid Chisnall { 1567a984708SDavid Chisnall public: 1577a984708SDavid Chisnall const_reference(const reference&) noexcept; 1587a984708SDavid Chisnall operator bool() const noexcept; 1597a984708SDavid Chisnall const_iterator operator&() const noexcept; 1607a984708SDavid Chisnall }; 1617a984708SDavid Chisnall 1627a984708SDavid Chisnall vector() 1637a984708SDavid Chisnall noexcept(is_nothrow_default_constructible<allocator_type>::value); 1647a984708SDavid Chisnall explicit vector(const allocator_type&); 1654f7ab58eSDimitry Andric explicit vector(size_type n, const allocator_type& a = allocator_type()); // C++14 1664f7ab58eSDimitry Andric vector(size_type n, const value_type& value, const allocator_type& = allocator_type()); 1677a984708SDavid Chisnall template <class InputIterator> 1687a984708SDavid Chisnall vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type()); 1697a984708SDavid Chisnall vector(const vector& x); 1707a984708SDavid Chisnall vector(vector&& x) 1717a984708SDavid Chisnall noexcept(is_nothrow_move_constructible<allocator_type>::value); 1727a984708SDavid Chisnall vector(initializer_list<value_type> il); 1737a984708SDavid Chisnall vector(initializer_list<value_type> il, const allocator_type& a); 1747a984708SDavid Chisnall ~vector(); 1757a984708SDavid Chisnall vector& operator=(const vector& x); 1767a984708SDavid Chisnall vector& operator=(vector&& x) 1777a984708SDavid Chisnall noexcept( 1789729cf09SDimitry Andric allocator_type::propagate_on_container_move_assignment::value || 1799729cf09SDimitry Andric allocator_type::is_always_equal::value); // C++17 1807a984708SDavid Chisnall vector& operator=(initializer_list<value_type> il); 1817a984708SDavid Chisnall template <class InputIterator> 1827a984708SDavid Chisnall void assign(InputIterator first, InputIterator last); 1837a984708SDavid Chisnall void assign(size_type n, const value_type& u); 1847a984708SDavid Chisnall void assign(initializer_list<value_type> il); 1857a984708SDavid Chisnall 1867a984708SDavid Chisnall allocator_type get_allocator() const noexcept; 1877a984708SDavid Chisnall 1887a984708SDavid Chisnall iterator begin() noexcept; 1897a984708SDavid Chisnall const_iterator begin() const noexcept; 1907a984708SDavid Chisnall iterator end() noexcept; 1917a984708SDavid Chisnall const_iterator end() const noexcept; 1927a984708SDavid Chisnall 1937a984708SDavid Chisnall reverse_iterator rbegin() noexcept; 1947a984708SDavid Chisnall const_reverse_iterator rbegin() const noexcept; 1957a984708SDavid Chisnall reverse_iterator rend() noexcept; 1967a984708SDavid Chisnall const_reverse_iterator rend() const noexcept; 1977a984708SDavid Chisnall 1987a984708SDavid Chisnall const_iterator cbegin() const noexcept; 1997a984708SDavid Chisnall const_iterator cend() const noexcept; 2007a984708SDavid Chisnall const_reverse_iterator crbegin() const noexcept; 2017a984708SDavid Chisnall const_reverse_iterator crend() const noexcept; 2027a984708SDavid Chisnall 2037a984708SDavid Chisnall size_type size() const noexcept; 2047a984708SDavid Chisnall size_type max_size() const noexcept; 2057a984708SDavid Chisnall size_type capacity() const noexcept; 2067a984708SDavid Chisnall bool empty() const noexcept; 2077a984708SDavid Chisnall void reserve(size_type n); 2087a984708SDavid Chisnall void shrink_to_fit() noexcept; 2097a984708SDavid Chisnall 2107a984708SDavid Chisnall reference operator[](size_type n); 2117a984708SDavid Chisnall const_reference operator[](size_type n) const; 2127a984708SDavid Chisnall reference at(size_type n); 2137a984708SDavid Chisnall const_reference at(size_type n) const; 2147a984708SDavid Chisnall 2157a984708SDavid Chisnall reference front(); 2167a984708SDavid Chisnall const_reference front() const; 2177a984708SDavid Chisnall reference back(); 2187a984708SDavid Chisnall const_reference back() const; 2197a984708SDavid Chisnall 2207a984708SDavid Chisnall void push_back(const value_type& x); 22198221d2eSDimitry Andric template <class... Args> reference emplace_back(Args&&... args); // C++14; reference in C++17 2227a984708SDavid Chisnall void pop_back(); 2237a984708SDavid Chisnall 2244f7ab58eSDimitry Andric template <class... Args> iterator emplace(const_iterator position, Args&&... args); // C++14 2257a984708SDavid Chisnall iterator insert(const_iterator position, const value_type& x); 2267a984708SDavid Chisnall iterator insert(const_iterator position, size_type n, const value_type& x); 2277a984708SDavid Chisnall template <class InputIterator> 2287a984708SDavid Chisnall iterator insert(const_iterator position, InputIterator first, InputIterator last); 2297a984708SDavid Chisnall iterator insert(const_iterator position, initializer_list<value_type> il); 2307a984708SDavid Chisnall 2317a984708SDavid Chisnall iterator erase(const_iterator position); 2327a984708SDavid Chisnall iterator erase(const_iterator first, const_iterator last); 2337a984708SDavid Chisnall 2347a984708SDavid Chisnall void clear() noexcept; 2357a984708SDavid Chisnall 2367a984708SDavid Chisnall void resize(size_type sz); 2377a984708SDavid Chisnall void resize(size_type sz, value_type x); 2387a984708SDavid Chisnall 2397a984708SDavid Chisnall void swap(vector&) 240854fa44bSDimitry Andric noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value || 241854fa44bSDimitry Andric allocator_traits<allocator_type>::is_always_equal::value); // C++17 2427a984708SDavid Chisnall void flip() noexcept; 2437a984708SDavid Chisnall 2447a984708SDavid Chisnall bool __invariants() const; 2457a984708SDavid Chisnall}; 2467a984708SDavid Chisnall 2474ba319b5SDimitry Andrictemplate <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>> 2484ba319b5SDimitry Andric vector(InputIterator, InputIterator, Allocator = Allocator()) 2494ba319b5SDimitry Andric -> vector<typename iterator_traits<InputIterator>::value_type, Allocator>; 2504ba319b5SDimitry Andric 2517a984708SDavid Chisnalltemplate <class Allocator> struct hash<std::vector<bool, Allocator>>; 2527a984708SDavid Chisnall 2537a984708SDavid Chisnalltemplate <class T, class Allocator> bool operator==(const vector<T,Allocator>& x, const vector<T,Allocator>& y); 2547a984708SDavid Chisnalltemplate <class T, class Allocator> bool operator< (const vector<T,Allocator>& x, const vector<T,Allocator>& y); 2557a984708SDavid Chisnalltemplate <class T, class Allocator> bool operator!=(const vector<T,Allocator>& x, const vector<T,Allocator>& y); 2567a984708SDavid Chisnalltemplate <class T, class Allocator> bool operator> (const vector<T,Allocator>& x, const vector<T,Allocator>& y); 2577a984708SDavid Chisnalltemplate <class T, class Allocator> bool operator>=(const vector<T,Allocator>& x, const vector<T,Allocator>& y); 2587a984708SDavid Chisnalltemplate <class T, class Allocator> bool operator<=(const vector<T,Allocator>& x, const vector<T,Allocator>& y); 2597a984708SDavid Chisnall 2607a984708SDavid Chisnalltemplate <class T, class Allocator> 2617a984708SDavid Chisnallvoid swap(vector<T,Allocator>& x, vector<T,Allocator>& y) 2627a984708SDavid Chisnall noexcept(noexcept(x.swap(y))); 2637a984708SDavid Chisnall 264*b5893f02SDimitry Andrictemplate <class T, class Allocator, class U> 265*b5893f02SDimitry Andric void erase(vector<T, Allocator>& c, const U& value); // C++20 266*b5893f02SDimitry Andrictemplate <class T, class Allocator, class Predicate> 267*b5893f02SDimitry Andric void erase_if(vector<T, Allocator>& c, Predicate pred); // C++20 268*b5893f02SDimitry Andric 2697a984708SDavid Chisnall} // std 2707a984708SDavid Chisnall 2717a984708SDavid Chisnall*/ 2727a984708SDavid Chisnall 2737a984708SDavid Chisnall#include <__config> 2747c82a1ecSDimitry Andric#include <iosfwd> // for forward declaration of vector 2757a984708SDavid Chisnall#include <__bit_reference> 2767a984708SDavid Chisnall#include <type_traits> 2777a984708SDavid Chisnall#include <climits> 2787a984708SDavid Chisnall#include <limits> 2797a984708SDavid Chisnall#include <initializer_list> 2807a984708SDavid Chisnall#include <memory> 2817a984708SDavid Chisnall#include <stdexcept> 2827a984708SDavid Chisnall#include <algorithm> 2837a984708SDavid Chisnall#include <cstring> 284*b5893f02SDimitry Andric#include <version> 2857a984708SDavid Chisnall#include <__split_buffer> 2867a984708SDavid Chisnall#include <__functional_base> 2877a984708SDavid Chisnall 2884f7ab58eSDimitry Andric#include <__debug> 2894f7ab58eSDimitry Andric 2907a984708SDavid Chisnall#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 2917a984708SDavid Chisnall#pragma GCC system_header 2927a984708SDavid Chisnall#endif 2937a984708SDavid Chisnall 294f9448bf3SDimitry Andric_LIBCPP_PUSH_MACROS 295f9448bf3SDimitry Andric#include <__undef_macros> 296f9448bf3SDimitry Andric 297f9448bf3SDimitry Andric 2987a984708SDavid Chisnall_LIBCPP_BEGIN_NAMESPACE_STD 2997a984708SDavid Chisnall 3007a984708SDavid Chisnalltemplate <bool> 3017a984708SDavid Chisnallclass __vector_base_common 3027a984708SDavid Chisnall{ 3037a984708SDavid Chisnallprotected: 3044ba319b5SDimitry Andric _LIBCPP_INLINE_VISIBILITY __vector_base_common() {} 305aed8d94eSDimitry Andric _LIBCPP_NORETURN void __throw_length_error() const; 306aed8d94eSDimitry Andric _LIBCPP_NORETURN void __throw_out_of_range() const; 3077a984708SDavid Chisnall}; 3087a984708SDavid Chisnall 3097a984708SDavid Chisnalltemplate <bool __b> 3107a984708SDavid Chisnallvoid 3117a984708SDavid Chisnall__vector_base_common<__b>::__throw_length_error() const 3127a984708SDavid Chisnall{ 313aed8d94eSDimitry Andric _VSTD::__throw_length_error("vector"); 3147a984708SDavid Chisnall} 3157a984708SDavid Chisnall 3167a984708SDavid Chisnalltemplate <bool __b> 3177a984708SDavid Chisnallvoid 3187a984708SDavid Chisnall__vector_base_common<__b>::__throw_out_of_range() const 3197a984708SDavid Chisnall{ 320aed8d94eSDimitry Andric _VSTD::__throw_out_of_range("vector"); 3217a984708SDavid Chisnall} 3227a984708SDavid Chisnall 323aed8d94eSDimitry Andric_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __vector_base_common<true>) 3247a984708SDavid Chisnall 3257a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 3267a984708SDavid Chisnallclass __vector_base 3277a984708SDavid Chisnall : protected __vector_base_common<true> 3287a984708SDavid Chisnall{ 3294ba319b5SDimitry Andricpublic: 3307a984708SDavid Chisnall typedef _Allocator allocator_type; 3317a984708SDavid Chisnall typedef allocator_traits<allocator_type> __alloc_traits; 3324ba319b5SDimitry Andric typedef typename __alloc_traits::size_type size_type; 3334ba319b5SDimitry Andricprotected: 3344ba319b5SDimitry Andric typedef _Tp value_type; 3357a984708SDavid Chisnall typedef value_type& reference; 3367a984708SDavid Chisnall typedef const value_type& const_reference; 3377a984708SDavid Chisnall typedef typename __alloc_traits::difference_type difference_type; 3387a984708SDavid Chisnall typedef typename __alloc_traits::pointer pointer; 3397a984708SDavid Chisnall typedef typename __alloc_traits::const_pointer const_pointer; 3407a984708SDavid Chisnall typedef pointer iterator; 3417a984708SDavid Chisnall typedef const_pointer const_iterator; 3427a984708SDavid Chisnall 3437a984708SDavid Chisnall pointer __begin_; 3447a984708SDavid Chisnall pointer __end_; 3457a984708SDavid Chisnall __compressed_pair<pointer, allocator_type> __end_cap_; 3467a984708SDavid Chisnall 3477a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 3487a984708SDavid Chisnall allocator_type& __alloc() _NOEXCEPT 3497a984708SDavid Chisnall {return __end_cap_.second();} 3507a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 3517a984708SDavid Chisnall const allocator_type& __alloc() const _NOEXCEPT 3527a984708SDavid Chisnall {return __end_cap_.second();} 3537a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 3547a984708SDavid Chisnall pointer& __end_cap() _NOEXCEPT 3557a984708SDavid Chisnall {return __end_cap_.first();} 3567a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 3577a984708SDavid Chisnall const pointer& __end_cap() const _NOEXCEPT 3587a984708SDavid Chisnall {return __end_cap_.first();} 3597a984708SDavid Chisnall 3607a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 3617a984708SDavid Chisnall __vector_base() 3627a984708SDavid Chisnall _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value); 3637a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY __vector_base(const allocator_type& __a); 3644ba319b5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 3654ba319b5SDimitry Andric _LIBCPP_INLINE_VISIBILITY __vector_base(allocator_type&& __a) _NOEXCEPT; 3664ba319b5SDimitry Andric#endif 3677a984708SDavid Chisnall ~__vector_base(); 3687a984708SDavid Chisnall 3697a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 3707a984708SDavid Chisnall void clear() _NOEXCEPT {__destruct_at_end(__begin_);} 3717a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 3727a984708SDavid Chisnall size_type capacity() const _NOEXCEPT 3737a984708SDavid Chisnall {return static_cast<size_type>(__end_cap() - __begin_);} 3747a984708SDavid Chisnall 3757a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 3764bab9fd9SDavid Chisnall void __destruct_at_end(pointer __new_last) _NOEXCEPT; 3777a984708SDavid Chisnall 3787a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 3797a984708SDavid Chisnall void __copy_assign_alloc(const __vector_base& __c) 3807a984708SDavid Chisnall {__copy_assign_alloc(__c, integral_constant<bool, 3817a984708SDavid Chisnall __alloc_traits::propagate_on_container_copy_assignment::value>());} 3827a984708SDavid Chisnall 3837a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 3847a984708SDavid Chisnall void __move_assign_alloc(__vector_base& __c) 3857a984708SDavid Chisnall _NOEXCEPT_( 3867a984708SDavid Chisnall !__alloc_traits::propagate_on_container_move_assignment::value || 3877a984708SDavid Chisnall is_nothrow_move_assignable<allocator_type>::value) 3887a984708SDavid Chisnall {__move_assign_alloc(__c, integral_constant<bool, 3897a984708SDavid Chisnall __alloc_traits::propagate_on_container_move_assignment::value>());} 3907a984708SDavid Chisnallprivate: 3917a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 3927a984708SDavid Chisnall void __copy_assign_alloc(const __vector_base& __c, true_type) 3937a984708SDavid Chisnall { 3947a984708SDavid Chisnall if (__alloc() != __c.__alloc()) 3957a984708SDavid Chisnall { 3967a984708SDavid Chisnall clear(); 3977a984708SDavid Chisnall __alloc_traits::deallocate(__alloc(), __begin_, capacity()); 3987a984708SDavid Chisnall __begin_ = __end_ = __end_cap() = nullptr; 3997a984708SDavid Chisnall } 4007a984708SDavid Chisnall __alloc() = __c.__alloc(); 4017a984708SDavid Chisnall } 4027a984708SDavid Chisnall 4037a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 40494e3ee44SDavid Chisnall void __copy_assign_alloc(const __vector_base&, false_type) 4057a984708SDavid Chisnall {} 4067a984708SDavid Chisnall 4077a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 4087a984708SDavid Chisnall void __move_assign_alloc(__vector_base& __c, true_type) 4097a984708SDavid Chisnall _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) 4107a984708SDavid Chisnall { 4117a984708SDavid Chisnall __alloc() = _VSTD::move(__c.__alloc()); 4127a984708SDavid Chisnall } 4137a984708SDavid Chisnall 4147a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 41594e3ee44SDavid Chisnall void __move_assign_alloc(__vector_base&, false_type) 4167a984708SDavid Chisnall _NOEXCEPT 4177a984708SDavid Chisnall {} 4187a984708SDavid Chisnall}; 4197a984708SDavid Chisnall 4207a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 4214f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 4227a984708SDavid Chisnallvoid 4234bab9fd9SDavid Chisnall__vector_base<_Tp, _Allocator>::__destruct_at_end(pointer __new_last) _NOEXCEPT 4247a984708SDavid Chisnall{ 425540d2a8bSDimitry Andric pointer __soon_to_be_end = __end_; 426540d2a8bSDimitry Andric while (__new_last != __soon_to_be_end) 427540d2a8bSDimitry Andric __alloc_traits::destroy(__alloc(), _VSTD::__to_raw_pointer(--__soon_to_be_end)); 428540d2a8bSDimitry Andric __end_ = __new_last; 4297a984708SDavid Chisnall} 4307a984708SDavid Chisnall 4317a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 4324f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 4337a984708SDavid Chisnall__vector_base<_Tp, _Allocator>::__vector_base() 4347a984708SDavid Chisnall _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) 4354bab9fd9SDavid Chisnall : __begin_(nullptr), 4364bab9fd9SDavid Chisnall __end_(nullptr), 4374bab9fd9SDavid Chisnall __end_cap_(nullptr) 4387a984708SDavid Chisnall{ 4397a984708SDavid Chisnall} 4407a984708SDavid Chisnall 4417a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 4424f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 4437a984708SDavid Chisnall__vector_base<_Tp, _Allocator>::__vector_base(const allocator_type& __a) 4444bab9fd9SDavid Chisnall : __begin_(nullptr), 4454bab9fd9SDavid Chisnall __end_(nullptr), 4464bab9fd9SDavid Chisnall __end_cap_(nullptr, __a) 4477a984708SDavid Chisnall{ 4487a984708SDavid Chisnall} 4497a984708SDavid Chisnall 4504ba319b5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 4514ba319b5SDimitry Andrictemplate <class _Tp, class _Allocator> 4524ba319b5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 4534ba319b5SDimitry Andric__vector_base<_Tp, _Allocator>::__vector_base(allocator_type&& __a) _NOEXCEPT 4544ba319b5SDimitry Andric : __begin_(nullptr), 4554ba319b5SDimitry Andric __end_(nullptr), 4564ba319b5SDimitry Andric __end_cap_(nullptr, std::move(__a)) {} 4574ba319b5SDimitry Andric#endif 4584ba319b5SDimitry Andric 4597a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 4607a984708SDavid Chisnall__vector_base<_Tp, _Allocator>::~__vector_base() 4617a984708SDavid Chisnall{ 4624bab9fd9SDavid Chisnall if (__begin_ != nullptr) 4637a984708SDavid Chisnall { 4647a984708SDavid Chisnall clear(); 4657a984708SDavid Chisnall __alloc_traits::deallocate(__alloc(), __begin_, capacity()); 4667a984708SDavid Chisnall } 4677a984708SDavid Chisnall} 4687a984708SDavid Chisnall 4697c82a1ecSDimitry Andrictemplate <class _Tp, class _Allocator /* = allocator<_Tp> */> 470aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS vector 4717a984708SDavid Chisnall : private __vector_base<_Tp, _Allocator> 4727a984708SDavid Chisnall{ 4737a984708SDavid Chisnallprivate: 4747a984708SDavid Chisnall typedef __vector_base<_Tp, _Allocator> __base; 475d72607e9SDimitry Andric typedef allocator<_Tp> __default_allocator_type; 4767a984708SDavid Chisnallpublic: 4777a984708SDavid Chisnall typedef vector __self; 4787a984708SDavid Chisnall typedef _Tp value_type; 4797a984708SDavid Chisnall typedef _Allocator allocator_type; 4807a984708SDavid Chisnall typedef typename __base::__alloc_traits __alloc_traits; 4817a984708SDavid Chisnall typedef typename __base::reference reference; 4827a984708SDavid Chisnall typedef typename __base::const_reference const_reference; 4837a984708SDavid Chisnall typedef typename __base::size_type size_type; 4847a984708SDavid Chisnall typedef typename __base::difference_type difference_type; 4857a984708SDavid Chisnall typedef typename __base::pointer pointer; 4867a984708SDavid Chisnall typedef typename __base::const_pointer const_pointer; 4877a984708SDavid Chisnall typedef __wrap_iter<pointer> iterator; 4887a984708SDavid Chisnall typedef __wrap_iter<const_pointer> const_iterator; 4897a984708SDavid Chisnall typedef _VSTD::reverse_iterator<iterator> reverse_iterator; 4907a984708SDavid Chisnall typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; 4917a984708SDavid Chisnall 4921bf9f7c1SDimitry Andric static_assert((is_same<typename allocator_type::value_type, value_type>::value), 4931bf9f7c1SDimitry Andric "Allocator::value_type must be same type as value_type"); 4941bf9f7c1SDimitry Andric 4957a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 496854fa44bSDimitry Andric vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) 4977a984708SDavid Chisnall { 4987a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2 4997a984708SDavid Chisnall __get_db()->__insert_c(this); 5007a984708SDavid Chisnall#endif 5017a984708SDavid Chisnall } 5027a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a) 503854fa44bSDimitry Andric#if _LIBCPP_STD_VER <= 14 504854fa44bSDimitry Andric _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value) 505854fa44bSDimitry Andric#else 506854fa44bSDimitry Andric _NOEXCEPT 507854fa44bSDimitry Andric#endif 5087a984708SDavid Chisnall : __base(__a) 5097a984708SDavid Chisnall { 5107a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2 5117a984708SDavid Chisnall __get_db()->__insert_c(this); 5127a984708SDavid Chisnall#endif 5137a984708SDavid Chisnall } 5147a984708SDavid Chisnall explicit vector(size_type __n); 5154f7ab58eSDimitry Andric#if _LIBCPP_STD_VER > 11 5164f7ab58eSDimitry Andric explicit vector(size_type __n, const allocator_type& __a); 5174f7ab58eSDimitry Andric#endif 5184ba319b5SDimitry Andric vector(size_type __n, const value_type& __x); 5194ba319b5SDimitry Andric vector(size_type __n, const value_type& __x, const allocator_type& __a); 5207a984708SDavid Chisnall template <class _InputIterator> 5214f7ab58eSDimitry Andric vector(_InputIterator __first, 5227a984708SDavid Chisnall typename enable_if<__is_input_iterator <_InputIterator>::value && 5231bf9f7c1SDimitry Andric !__is_forward_iterator<_InputIterator>::value && 5241bf9f7c1SDimitry Andric is_constructible< 5251bf9f7c1SDimitry Andric value_type, 5264f7ab58eSDimitry Andric typename iterator_traits<_InputIterator>::reference>::value, 5274f7ab58eSDimitry Andric _InputIterator>::type __last); 5287a984708SDavid Chisnall template <class _InputIterator> 5297a984708SDavid Chisnall vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, 5307a984708SDavid Chisnall typename enable_if<__is_input_iterator <_InputIterator>::value && 5311bf9f7c1SDimitry Andric !__is_forward_iterator<_InputIterator>::value && 5321bf9f7c1SDimitry Andric is_constructible< 5331bf9f7c1SDimitry Andric value_type, 5341bf9f7c1SDimitry Andric typename iterator_traits<_InputIterator>::reference>::value>::type* = 0); 5357a984708SDavid Chisnall template <class _ForwardIterator> 5364f7ab58eSDimitry Andric vector(_ForwardIterator __first, 5371bf9f7c1SDimitry Andric typename enable_if<__is_forward_iterator<_ForwardIterator>::value && 5381bf9f7c1SDimitry Andric is_constructible< 5391bf9f7c1SDimitry Andric value_type, 5404f7ab58eSDimitry Andric typename iterator_traits<_ForwardIterator>::reference>::value, 5414f7ab58eSDimitry Andric _ForwardIterator>::type __last); 5427a984708SDavid Chisnall template <class _ForwardIterator> 5437a984708SDavid Chisnall vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, 5441bf9f7c1SDimitry Andric typename enable_if<__is_forward_iterator<_ForwardIterator>::value && 5451bf9f7c1SDimitry Andric is_constructible< 5461bf9f7c1SDimitry Andric value_type, 5471bf9f7c1SDimitry Andric typename iterator_traits<_ForwardIterator>::reference>::value>::type* = 0); 548540d2a8bSDimitry Andric 5497a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 5507a984708SDavid Chisnall ~vector() 5517a984708SDavid Chisnall { 552*b5893f02SDimitry Andric __annotate_delete(); 553*b5893f02SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 5547a984708SDavid Chisnall __get_db()->__erase_c(this); 5557a984708SDavid Chisnall#endif 556*b5893f02SDimitry Andric } 5577a984708SDavid Chisnall 5587a984708SDavid Chisnall vector(const vector& __x); 5597a984708SDavid Chisnall vector(const vector& __x, const allocator_type& __a); 5607a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 5617a984708SDavid Chisnall vector& operator=(const vector& __x); 562540d2a8bSDimitry Andric 563540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG 564540d2a8bSDimitry Andric _LIBCPP_INLINE_VISIBILITY 565540d2a8bSDimitry Andric vector(initializer_list<value_type> __il); 566540d2a8bSDimitry Andric 567540d2a8bSDimitry Andric _LIBCPP_INLINE_VISIBILITY 568540d2a8bSDimitry Andric vector(initializer_list<value_type> __il, const allocator_type& __a); 569540d2a8bSDimitry Andric 5707a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 5717a984708SDavid Chisnall vector(vector&& __x) 572854fa44bSDimitry Andric#if _LIBCPP_STD_VER > 14 573854fa44bSDimitry Andric _NOEXCEPT; 574854fa44bSDimitry Andric#else 5757a984708SDavid Chisnall _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); 576854fa44bSDimitry Andric#endif 577540d2a8bSDimitry Andric 5787a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 5797a984708SDavid Chisnall vector(vector&& __x, const allocator_type& __a); 5807a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 5817a984708SDavid Chisnall vector& operator=(vector&& __x) 5829729cf09SDimitry Andric _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)); 583540d2a8bSDimitry Andric 5847a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 5857a984708SDavid Chisnall vector& operator=(initializer_list<value_type> __il) 5867a984708SDavid Chisnall {assign(__il.begin(), __il.end()); return *this;} 587540d2a8bSDimitry Andric 588540d2a8bSDimitry Andric#endif // !_LIBCPP_CXX03_LANG 5897a984708SDavid Chisnall 5907a984708SDavid Chisnall template <class _InputIterator> 5917a984708SDavid Chisnall typename enable_if 5927a984708SDavid Chisnall < 5937a984708SDavid Chisnall __is_input_iterator <_InputIterator>::value && 5941bf9f7c1SDimitry Andric !__is_forward_iterator<_InputIterator>::value && 5951bf9f7c1SDimitry Andric is_constructible< 5961bf9f7c1SDimitry Andric value_type, 5971bf9f7c1SDimitry Andric typename iterator_traits<_InputIterator>::reference>::value, 5987a984708SDavid Chisnall void 5997a984708SDavid Chisnall >::type 6007a984708SDavid Chisnall assign(_InputIterator __first, _InputIterator __last); 6017a984708SDavid Chisnall template <class _ForwardIterator> 6027a984708SDavid Chisnall typename enable_if 6037a984708SDavid Chisnall < 6041bf9f7c1SDimitry Andric __is_forward_iterator<_ForwardIterator>::value && 6051bf9f7c1SDimitry Andric is_constructible< 6061bf9f7c1SDimitry Andric value_type, 6071bf9f7c1SDimitry Andric typename iterator_traits<_ForwardIterator>::reference>::value, 6087a984708SDavid Chisnall void 6097a984708SDavid Chisnall >::type 6107a984708SDavid Chisnall assign(_ForwardIterator __first, _ForwardIterator __last); 6117a984708SDavid Chisnall 6127a984708SDavid Chisnall void assign(size_type __n, const_reference __u); 613540d2a8bSDimitry Andric 614540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG 6157a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 6167a984708SDavid Chisnall void assign(initializer_list<value_type> __il) 6177a984708SDavid Chisnall {assign(__il.begin(), __il.end());} 618540d2a8bSDimitry Andric#endif 6197a984708SDavid Chisnall 6207a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 6217a984708SDavid Chisnall allocator_type get_allocator() const _NOEXCEPT 6227a984708SDavid Chisnall {return this->__alloc();} 6237a984708SDavid Chisnall 6247a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT; 6257a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT; 6267a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT; 6277a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT; 6287a984708SDavid Chisnall 6297a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 6307a984708SDavid Chisnall reverse_iterator rbegin() _NOEXCEPT 6317a984708SDavid Chisnall {return reverse_iterator(end());} 6327a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 6337a984708SDavid Chisnall const_reverse_iterator rbegin() const _NOEXCEPT 6347a984708SDavid Chisnall {return const_reverse_iterator(end());} 6357a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 6367a984708SDavid Chisnall reverse_iterator rend() _NOEXCEPT 6377a984708SDavid Chisnall {return reverse_iterator(begin());} 6387a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 6397a984708SDavid Chisnall const_reverse_iterator rend() const _NOEXCEPT 6407a984708SDavid Chisnall {return const_reverse_iterator(begin());} 6417a984708SDavid Chisnall 6427a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 6437a984708SDavid Chisnall const_iterator cbegin() const _NOEXCEPT 6447a984708SDavid Chisnall {return begin();} 6457a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 6467a984708SDavid Chisnall const_iterator cend() const _NOEXCEPT 6477a984708SDavid Chisnall {return end();} 6487a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 6497a984708SDavid Chisnall const_reverse_iterator crbegin() const _NOEXCEPT 6507a984708SDavid Chisnall {return rbegin();} 6517a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 6527a984708SDavid Chisnall const_reverse_iterator crend() const _NOEXCEPT 6537a984708SDavid Chisnall {return rend();} 6547a984708SDavid Chisnall 6557a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 6567a984708SDavid Chisnall size_type size() const _NOEXCEPT 6577a984708SDavid Chisnall {return static_cast<size_type>(this->__end_ - this->__begin_);} 6587a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 6597a984708SDavid Chisnall size_type capacity() const _NOEXCEPT 6607a984708SDavid Chisnall {return __base::capacity();} 661b2c7081bSDimitry Andric _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 6627a984708SDavid Chisnall bool empty() const _NOEXCEPT 6637a984708SDavid Chisnall {return this->__begin_ == this->__end_;} 6647a984708SDavid Chisnall size_type max_size() const _NOEXCEPT; 6657a984708SDavid Chisnall void reserve(size_type __n); 6667a984708SDavid Chisnall void shrink_to_fit() _NOEXCEPT; 6677a984708SDavid Chisnall 6687a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n); 6697a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const; 6707a984708SDavid Chisnall reference at(size_type __n); 6717a984708SDavid Chisnall const_reference at(size_type __n) const; 6727a984708SDavid Chisnall 6737a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY reference front() 6747a984708SDavid Chisnall { 6757a984708SDavid Chisnall _LIBCPP_ASSERT(!empty(), "front() called for empty vector"); 6767a984708SDavid Chisnall return *this->__begin_; 6777a984708SDavid Chisnall } 6787a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY const_reference front() const 6797a984708SDavid Chisnall { 6807a984708SDavid Chisnall _LIBCPP_ASSERT(!empty(), "front() called for empty vector"); 6817a984708SDavid Chisnall return *this->__begin_; 6827a984708SDavid Chisnall } 6837a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY reference back() 6847a984708SDavid Chisnall { 6857a984708SDavid Chisnall _LIBCPP_ASSERT(!empty(), "back() called for empty vector"); 6867a984708SDavid Chisnall return *(this->__end_ - 1); 6877a984708SDavid Chisnall } 6887a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY const_reference back() const 6897a984708SDavid Chisnall { 6907a984708SDavid Chisnall _LIBCPP_ASSERT(!empty(), "back() called for empty vector"); 6917a984708SDavid Chisnall return *(this->__end_ - 1); 6927a984708SDavid Chisnall } 6937a984708SDavid Chisnall 6947a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 6957a984708SDavid Chisnall value_type* data() _NOEXCEPT 6967a984708SDavid Chisnall {return _VSTD::__to_raw_pointer(this->__begin_);} 6977a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 6987a984708SDavid Chisnall const value_type* data() const _NOEXCEPT 6997a984708SDavid Chisnall {return _VSTD::__to_raw_pointer(this->__begin_);} 7007a984708SDavid Chisnall 701d4419f6fSDimitry Andric#ifdef _LIBCPP_CXX03_LANG 702d4419f6fSDimitry Andric _LIBCPP_INLINE_VISIBILITY 703d4419f6fSDimitry Andric void __emplace_back(const value_type& __x) { push_back(__x); } 704d4419f6fSDimitry Andric#else 705d4419f6fSDimitry Andric template <class _Arg> 706d4419f6fSDimitry Andric _LIBCPP_INLINE_VISIBILITY 707d4419f6fSDimitry Andric void __emplace_back(_Arg&& __arg) { 708d4419f6fSDimitry Andric emplace_back(_VSTD::forward<_Arg>(__arg)); 709d4419f6fSDimitry Andric } 710d4419f6fSDimitry Andric#endif 711d4419f6fSDimitry Andric 7127a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x); 713540d2a8bSDimitry Andric 714540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG 71594e3ee44SDavid Chisnall _LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x); 716540d2a8bSDimitry Andric 7177a984708SDavid Chisnall template <class... _Args> 7189729cf09SDimitry Andric _LIBCPP_INLINE_VISIBILITY 71998221d2eSDimitry Andric#if _LIBCPP_STD_VER > 14 720aed8d94eSDimitry Andric reference emplace_back(_Args&&... __args); 72198221d2eSDimitry Andric#else 72298221d2eSDimitry Andric void emplace_back(_Args&&... __args); 72398221d2eSDimitry Andric#endif 724540d2a8bSDimitry Andric#endif // !_LIBCPP_CXX03_LANG 725540d2a8bSDimitry Andric 7269729cf09SDimitry Andric _LIBCPP_INLINE_VISIBILITY 7277a984708SDavid Chisnall void pop_back(); 7287a984708SDavid Chisnall 7297a984708SDavid Chisnall iterator insert(const_iterator __position, const_reference __x); 730540d2a8bSDimitry Andric 731540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG 7327a984708SDavid Chisnall iterator insert(const_iterator __position, value_type&& __x); 7337a984708SDavid Chisnall template <class... _Args> 7347a984708SDavid Chisnall iterator emplace(const_iterator __position, _Args&&... __args); 735540d2a8bSDimitry Andric#endif // !_LIBCPP_CXX03_LANG 736540d2a8bSDimitry Andric 7377a984708SDavid Chisnall iterator insert(const_iterator __position, size_type __n, const_reference __x); 7387a984708SDavid Chisnall template <class _InputIterator> 7397a984708SDavid Chisnall typename enable_if 7407a984708SDavid Chisnall < 7417a984708SDavid Chisnall __is_input_iterator <_InputIterator>::value && 7421bf9f7c1SDimitry Andric !__is_forward_iterator<_InputIterator>::value && 7431bf9f7c1SDimitry Andric is_constructible< 7441bf9f7c1SDimitry Andric value_type, 7451bf9f7c1SDimitry Andric typename iterator_traits<_InputIterator>::reference>::value, 7467a984708SDavid Chisnall iterator 7477a984708SDavid Chisnall >::type 7487a984708SDavid Chisnall insert(const_iterator __position, _InputIterator __first, _InputIterator __last); 7497a984708SDavid Chisnall template <class _ForwardIterator> 7507a984708SDavid Chisnall typename enable_if 7517a984708SDavid Chisnall < 7521bf9f7c1SDimitry Andric __is_forward_iterator<_ForwardIterator>::value && 7531bf9f7c1SDimitry Andric is_constructible< 7541bf9f7c1SDimitry Andric value_type, 7551bf9f7c1SDimitry Andric typename iterator_traits<_ForwardIterator>::reference>::value, 7567a984708SDavid Chisnall iterator 7577a984708SDavid Chisnall >::type 7587a984708SDavid Chisnall insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last); 759540d2a8bSDimitry Andric 760540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG 7617a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 7627a984708SDavid Chisnall iterator insert(const_iterator __position, initializer_list<value_type> __il) 7637a984708SDavid Chisnall {return insert(__position, __il.begin(), __il.end());} 764540d2a8bSDimitry Andric#endif 7657a984708SDavid Chisnall 7667a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position); 7677a984708SDavid Chisnall iterator erase(const_iterator __first, const_iterator __last); 7687a984708SDavid Chisnall 7697a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 7707a984708SDavid Chisnall void clear() _NOEXCEPT 7717a984708SDavid Chisnall { 772d72607e9SDimitry Andric size_type __old_size = size(); 7737a984708SDavid Chisnall __base::clear(); 774d72607e9SDimitry Andric __annotate_shrink(__old_size); 7757a984708SDavid Chisnall __invalidate_all_iterators(); 7767a984708SDavid Chisnall } 7777a984708SDavid Chisnall 7787a984708SDavid Chisnall void resize(size_type __sz); 7797a984708SDavid Chisnall void resize(size_type __sz, const_reference __x); 7807a984708SDavid Chisnall 7817a984708SDavid Chisnall void swap(vector&) 782854fa44bSDimitry Andric#if _LIBCPP_STD_VER >= 14 783aed8d94eSDimitry Andric _NOEXCEPT_DEBUG; 784854fa44bSDimitry Andric#else 785aed8d94eSDimitry Andric _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value || 7867a984708SDavid Chisnall __is_nothrow_swappable<allocator_type>::value); 787854fa44bSDimitry Andric#endif 7887a984708SDavid Chisnall 7897a984708SDavid Chisnall bool __invariants() const; 7907a984708SDavid Chisnall 7917a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2 7927a984708SDavid Chisnall 7937a984708SDavid Chisnall bool __dereferenceable(const const_iterator* __i) const; 7947a984708SDavid Chisnall bool __decrementable(const const_iterator* __i) const; 7957a984708SDavid Chisnall bool __addable(const const_iterator* __i, ptrdiff_t __n) const; 7967a984708SDavid Chisnall bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const; 7977a984708SDavid Chisnall 7987a984708SDavid Chisnall#endif // _LIBCPP_DEBUG_LEVEL >= 2 7997a984708SDavid Chisnall 8007a984708SDavid Chisnallprivate: 8017a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators(); 802aed8d94eSDimitry Andric _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(pointer __new_last); 8034ba319b5SDimitry Andric void __vallocate(size_type __n); 8044ba319b5SDimitry Andric void __vdeallocate() _NOEXCEPT; 8057a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const; 8067a984708SDavid Chisnall void __construct_at_end(size_type __n); 8079729cf09SDimitry Andric _LIBCPP_INLINE_VISIBILITY 8087a984708SDavid Chisnall void __construct_at_end(size_type __n, const_reference __x); 8097a984708SDavid Chisnall template <class _ForwardIterator> 8107a984708SDavid Chisnall typename enable_if 8117a984708SDavid Chisnall < 8127a984708SDavid Chisnall __is_forward_iterator<_ForwardIterator>::value, 8137a984708SDavid Chisnall void 8147a984708SDavid Chisnall >::type 815854fa44bSDimitry Andric __construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n); 8167a984708SDavid Chisnall void __append(size_type __n); 8177a984708SDavid Chisnall void __append(size_type __n, const_reference __x); 8187a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 8197a984708SDavid Chisnall iterator __make_iter(pointer __p) _NOEXCEPT; 8207a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 8217a984708SDavid Chisnall const_iterator __make_iter(const_pointer __p) const _NOEXCEPT; 8227a984708SDavid Chisnall void __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v); 8237a984708SDavid Chisnall pointer __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p); 8247a984708SDavid Chisnall void __move_range(pointer __from_s, pointer __from_e, pointer __to); 8257a984708SDavid Chisnall void __move_assign(vector& __c, true_type) 8267a984708SDavid Chisnall _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); 8279729cf09SDimitry Andric void __move_assign(vector& __c, false_type) 8289729cf09SDimitry Andric _NOEXCEPT_(__alloc_traits::is_always_equal::value); 8297a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 8304bab9fd9SDavid Chisnall void __destruct_at_end(pointer __new_last) _NOEXCEPT 8317a984708SDavid Chisnall { 832aed8d94eSDimitry Andric __invalidate_iterators_past(__new_last); 833d72607e9SDimitry Andric size_type __old_size = size(); 8347a984708SDavid Chisnall __base::__destruct_at_end(__new_last); 835d72607e9SDimitry Andric __annotate_shrink(__old_size); 8367a984708SDavid Chisnall } 837540d2a8bSDimitry Andric 838540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG 839540d2a8bSDimitry Andric template <class _Up> void __push_back_slow_path(_Up&& __x); 840540d2a8bSDimitry Andric 84194e3ee44SDavid Chisnall template <class... _Args> 842540d2a8bSDimitry Andric void __emplace_back_slow_path(_Args&&... __args); 843540d2a8bSDimitry Andric#else 844540d2a8bSDimitry Andric template <class _Up> void __push_back_slow_path(_Up& __x); 84594e3ee44SDavid Chisnall#endif 846540d2a8bSDimitry Andric 847d72607e9SDimitry Andric // The following functions are no-ops outside of AddressSanitizer mode. 848d72607e9SDimitry Andric // We call annotatations only for the default Allocator because other allocators 849d72607e9SDimitry Andric // may not meet the AddressSanitizer alignment constraints. 850d72607e9SDimitry Andric // See the documentation for __sanitizer_annotate_contiguous_container for more details. 851d72607e9SDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN 852aed8d94eSDimitry Andric void __annotate_contiguous_container(const void *__beg, const void *__end, 853aed8d94eSDimitry Andric const void *__old_mid, 854aed8d94eSDimitry Andric const void *__new_mid) const 855aed8d94eSDimitry Andric { 856aed8d94eSDimitry Andric 857d72607e9SDimitry Andric if (__beg && is_same<allocator_type, __default_allocator_type>::value) 858d72607e9SDimitry Andric __sanitizer_annotate_contiguous_container(__beg, __end, __old_mid, __new_mid); 859d72607e9SDimitry Andric } 860aed8d94eSDimitry Andric#else 861aed8d94eSDimitry Andric _LIBCPP_INLINE_VISIBILITY 862aed8d94eSDimitry Andric void __annotate_contiguous_container(const void*, const void*, const void*, 863aed8d94eSDimitry Andric const void*) const {} 864aed8d94eSDimitry Andric#endif 865aed8d94eSDimitry Andric _LIBCPP_INLINE_VISIBILITY 866aed8d94eSDimitry Andric void __annotate_new(size_type __current_size) const { 867d72607e9SDimitry Andric __annotate_contiguous_container(data(), data() + capacity(), 868d72607e9SDimitry Andric data() + capacity(), data() + __current_size); 869d72607e9SDimitry Andric } 870aed8d94eSDimitry Andric 871aed8d94eSDimitry Andric _LIBCPP_INLINE_VISIBILITY 872aed8d94eSDimitry Andric void __annotate_delete() const { 873d72607e9SDimitry Andric __annotate_contiguous_container(data(), data() + capacity(), 874d72607e9SDimitry Andric data() + size(), data() + capacity()); 875d72607e9SDimitry Andric } 876aed8d94eSDimitry Andric 877aed8d94eSDimitry Andric _LIBCPP_INLINE_VISIBILITY 878d72607e9SDimitry Andric void __annotate_increase(size_type __n) const 879d72607e9SDimitry Andric { 880d72607e9SDimitry Andric __annotate_contiguous_container(data(), data() + capacity(), 881d72607e9SDimitry Andric data() + size(), data() + size() + __n); 882d72607e9SDimitry Andric } 883aed8d94eSDimitry Andric 884aed8d94eSDimitry Andric _LIBCPP_INLINE_VISIBILITY 885d72607e9SDimitry Andric void __annotate_shrink(size_type __old_size) const 886d72607e9SDimitry Andric { 887d72607e9SDimitry Andric __annotate_contiguous_container(data(), data() + capacity(), 888d72607e9SDimitry Andric data() + __old_size, data() + size()); 889d72607e9SDimitry Andric } 890d72607e9SDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN 891d72607e9SDimitry Andric // The annotation for size increase should happen before the actual increase, 892d72607e9SDimitry Andric // but if an exception is thrown after that the annotation has to be undone. 893d72607e9SDimitry Andric struct __RAII_IncreaseAnnotator { 894d72607e9SDimitry Andric __RAII_IncreaseAnnotator(const vector &__v, size_type __n = 1) 895854fa44bSDimitry Andric : __commit(false), __v(__v), __old_size(__v.size() + __n) { 896d72607e9SDimitry Andric __v.__annotate_increase(__n); 897d72607e9SDimitry Andric } 898d72607e9SDimitry Andric void __done() { __commit = true; } 899d72607e9SDimitry Andric ~__RAII_IncreaseAnnotator() { 900d72607e9SDimitry Andric if (__commit) return; 901854fa44bSDimitry Andric __v.__annotate_shrink(__old_size); 902d72607e9SDimitry Andric } 903d72607e9SDimitry Andric bool __commit; 904d72607e9SDimitry Andric const vector &__v; 905854fa44bSDimitry Andric size_type __old_size; 906d72607e9SDimitry Andric }; 907d72607e9SDimitry Andric#else 908d72607e9SDimitry Andric struct __RAII_IncreaseAnnotator { 909aed8d94eSDimitry Andric _LIBCPP_INLINE_VISIBILITY 910aed8d94eSDimitry Andric __RAII_IncreaseAnnotator(const vector &, size_type = 1) {} 911aed8d94eSDimitry Andric _LIBCPP_INLINE_VISIBILITY void __done() {} 912d72607e9SDimitry Andric }; 913d72607e9SDimitry Andric#endif 914d72607e9SDimitry Andric 9157a984708SDavid Chisnall}; 9167a984708SDavid Chisnall 9174ba319b5SDimitry Andric#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES 9184ba319b5SDimitry Andrictemplate<class _InputIterator, 9194ba319b5SDimitry Andric class _Alloc = typename std::allocator<typename iterator_traits<_InputIterator>::value_type>, 9204ba319b5SDimitry Andric class = typename enable_if<__is_allocator<_Alloc>::value, void>::type 9214ba319b5SDimitry Andric > 9224ba319b5SDimitry Andricvector(_InputIterator, _InputIterator) 9234ba319b5SDimitry Andric -> vector<typename iterator_traits<_InputIterator>::value_type, _Alloc>; 9244ba319b5SDimitry Andric 9254ba319b5SDimitry Andrictemplate<class _InputIterator, 9264ba319b5SDimitry Andric class _Alloc, 9274ba319b5SDimitry Andric class = typename enable_if<__is_allocator<_Alloc>::value, void>::type 9284ba319b5SDimitry Andric > 9294ba319b5SDimitry Andricvector(_InputIterator, _InputIterator, _Alloc) 9304ba319b5SDimitry Andric -> vector<typename iterator_traits<_InputIterator>::value_type, _Alloc>; 9314ba319b5SDimitry Andric#endif 9324ba319b5SDimitry Andric 9337a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 9347a984708SDavid Chisnallvoid 9357a984708SDavid Chisnallvector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v) 9367a984708SDavid Chisnall{ 937d72607e9SDimitry Andric __annotate_delete(); 93894e3ee44SDavid Chisnall __alloc_traits::__construct_backward(this->__alloc(), this->__begin_, this->__end_, __v.__begin_); 9397a984708SDavid Chisnall _VSTD::swap(this->__begin_, __v.__begin_); 9407a984708SDavid Chisnall _VSTD::swap(this->__end_, __v.__end_); 9417a984708SDavid Chisnall _VSTD::swap(this->__end_cap(), __v.__end_cap()); 9427a984708SDavid Chisnall __v.__first_ = __v.__begin_; 943d72607e9SDimitry Andric __annotate_new(size()); 9447a984708SDavid Chisnall __invalidate_all_iterators(); 9457a984708SDavid Chisnall} 9467a984708SDavid Chisnall 9477a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 9487a984708SDavid Chisnalltypename vector<_Tp, _Allocator>::pointer 9497a984708SDavid Chisnallvector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p) 9507a984708SDavid Chisnall{ 951d72607e9SDimitry Andric __annotate_delete(); 9527a984708SDavid Chisnall pointer __r = __v.__begin_; 95394e3ee44SDavid Chisnall __alloc_traits::__construct_backward(this->__alloc(), this->__begin_, __p, __v.__begin_); 95494e3ee44SDavid Chisnall __alloc_traits::__construct_forward(this->__alloc(), __p, this->__end_, __v.__end_); 9557a984708SDavid Chisnall _VSTD::swap(this->__begin_, __v.__begin_); 9567a984708SDavid Chisnall _VSTD::swap(this->__end_, __v.__end_); 9577a984708SDavid Chisnall _VSTD::swap(this->__end_cap(), __v.__end_cap()); 9587a984708SDavid Chisnall __v.__first_ = __v.__begin_; 959d72607e9SDimitry Andric __annotate_new(size()); 9607a984708SDavid Chisnall __invalidate_all_iterators(); 9617a984708SDavid Chisnall return __r; 9627a984708SDavid Chisnall} 9637a984708SDavid Chisnall 9647a984708SDavid Chisnall// Allocate space for __n objects 9657a984708SDavid Chisnall// throws length_error if __n > max_size() 9667a984708SDavid Chisnall// throws (probably bad_alloc) if memory run out 9677a984708SDavid Chisnall// Precondition: __begin_ == __end_ == __end_cap() == 0 9687a984708SDavid Chisnall// Precondition: __n > 0 9697a984708SDavid Chisnall// Postcondition: capacity() == __n 9707a984708SDavid Chisnall// Postcondition: size() == 0 9717a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 9727a984708SDavid Chisnallvoid 9734ba319b5SDimitry Andricvector<_Tp, _Allocator>::__vallocate(size_type __n) 9747a984708SDavid Chisnall{ 9757a984708SDavid Chisnall if (__n > max_size()) 9767a984708SDavid Chisnall this->__throw_length_error(); 9777a984708SDavid Chisnall this->__begin_ = this->__end_ = __alloc_traits::allocate(this->__alloc(), __n); 9787a984708SDavid Chisnall this->__end_cap() = this->__begin_ + __n; 979d72607e9SDimitry Andric __annotate_new(0); 9807a984708SDavid Chisnall} 9817a984708SDavid Chisnall 9827a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 9837a984708SDavid Chisnallvoid 9844ba319b5SDimitry Andricvector<_Tp, _Allocator>::__vdeallocate() _NOEXCEPT 9857a984708SDavid Chisnall{ 9864bab9fd9SDavid Chisnall if (this->__begin_ != nullptr) 9877a984708SDavid Chisnall { 9887a984708SDavid Chisnall clear(); 9897a984708SDavid Chisnall __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity()); 9904bab9fd9SDavid Chisnall this->__begin_ = this->__end_ = this->__end_cap() = nullptr; 9917a984708SDavid Chisnall } 9927a984708SDavid Chisnall} 9937a984708SDavid Chisnall 9947a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 9957a984708SDavid Chisnalltypename vector<_Tp, _Allocator>::size_type 9967a984708SDavid Chisnallvector<_Tp, _Allocator>::max_size() const _NOEXCEPT 9977a984708SDavid Chisnall{ 998aed8d94eSDimitry Andric return _VSTD::min<size_type>(__alloc_traits::max_size(this->__alloc()), 999aed8d94eSDimitry Andric numeric_limits<difference_type>::max()); 10007a984708SDavid Chisnall} 10017a984708SDavid Chisnall 10027a984708SDavid Chisnall// Precondition: __new_size > capacity() 10037a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 10044f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 10057a984708SDavid Chisnalltypename vector<_Tp, _Allocator>::size_type 10067a984708SDavid Chisnallvector<_Tp, _Allocator>::__recommend(size_type __new_size) const 10077a984708SDavid Chisnall{ 10087a984708SDavid Chisnall const size_type __ms = max_size(); 10097a984708SDavid Chisnall if (__new_size > __ms) 10107a984708SDavid Chisnall this->__throw_length_error(); 10117a984708SDavid Chisnall const size_type __cap = capacity(); 10127a984708SDavid Chisnall if (__cap >= __ms / 2) 10137a984708SDavid Chisnall return __ms; 10147a984708SDavid Chisnall return _VSTD::max<size_type>(2*__cap, __new_size); 10157a984708SDavid Chisnall} 10167a984708SDavid Chisnall 10177a984708SDavid Chisnall// Default constructs __n objects starting at __end_ 10187a984708SDavid Chisnall// throws if construction throws 10197a984708SDavid Chisnall// Precondition: __n > 0 10207a984708SDavid Chisnall// Precondition: size() + __n <= capacity() 10217a984708SDavid Chisnall// Postcondition: size() == size() + __n 10227a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 10237a984708SDavid Chisnallvoid 10247a984708SDavid Chisnallvector<_Tp, _Allocator>::__construct_at_end(size_type __n) 10257a984708SDavid Chisnall{ 10267a984708SDavid Chisnall allocator_type& __a = this->__alloc(); 10277a984708SDavid Chisnall do 10287a984708SDavid Chisnall { 1029d72607e9SDimitry Andric __RAII_IncreaseAnnotator __annotator(*this); 10307a984708SDavid Chisnall __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_)); 10317a984708SDavid Chisnall ++this->__end_; 10327a984708SDavid Chisnall --__n; 1033d72607e9SDimitry Andric __annotator.__done(); 10347a984708SDavid Chisnall } while (__n > 0); 10357a984708SDavid Chisnall} 10367a984708SDavid Chisnall 10377a984708SDavid Chisnall// Copy constructs __n objects starting at __end_ from __x 10387a984708SDavid Chisnall// throws if construction throws 10397a984708SDavid Chisnall// Precondition: __n > 0 10407a984708SDavid Chisnall// Precondition: size() + __n <= capacity() 10417a984708SDavid Chisnall// Postcondition: size() == old size() + __n 10427a984708SDavid Chisnall// Postcondition: [i] == __x for all i in [size() - __n, __n) 10437a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 10449729cf09SDimitry Andricinline 10457a984708SDavid Chisnallvoid 10467a984708SDavid Chisnallvector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x) 10477a984708SDavid Chisnall{ 10487a984708SDavid Chisnall allocator_type& __a = this->__alloc(); 10497a984708SDavid Chisnall do 10507a984708SDavid Chisnall { 1051d72607e9SDimitry Andric __RAII_IncreaseAnnotator __annotator(*this); 10527a984708SDavid Chisnall __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), __x); 10537a984708SDavid Chisnall ++this->__end_; 10547a984708SDavid Chisnall --__n; 1055d72607e9SDimitry Andric __annotator.__done(); 10567a984708SDavid Chisnall } while (__n > 0); 10577a984708SDavid Chisnall} 10587a984708SDavid Chisnall 10597a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 10607a984708SDavid Chisnalltemplate <class _ForwardIterator> 10617a984708SDavid Chisnalltypename enable_if 10627a984708SDavid Chisnall< 10637a984708SDavid Chisnall __is_forward_iterator<_ForwardIterator>::value, 10647a984708SDavid Chisnall void 10657a984708SDavid Chisnall>::type 1066854fa44bSDimitry Andricvector<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n) 10677a984708SDavid Chisnall{ 10687a984708SDavid Chisnall allocator_type& __a = this->__alloc(); 1069854fa44bSDimitry Andric __RAII_IncreaseAnnotator __annotator(*this, __n); 1070854fa44bSDimitry Andric __alloc_traits::__construct_range_forward(__a, __first, __last, this->__end_); 1071d72607e9SDimitry Andric __annotator.__done(); 10727a984708SDavid Chisnall} 10737a984708SDavid Chisnall 10747a984708SDavid Chisnall// Default constructs __n objects starting at __end_ 10757a984708SDavid Chisnall// throws if construction throws 10767a984708SDavid Chisnall// Postcondition: size() == size() + __n 10777a984708SDavid Chisnall// Exception safety: strong. 10787a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 10797a984708SDavid Chisnallvoid 10807a984708SDavid Chisnallvector<_Tp, _Allocator>::__append(size_type __n) 10817a984708SDavid Chisnall{ 10827a984708SDavid Chisnall if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n) 10837a984708SDavid Chisnall this->__construct_at_end(__n); 10847a984708SDavid Chisnall else 10857a984708SDavid Chisnall { 10867a984708SDavid Chisnall allocator_type& __a = this->__alloc(); 10877a984708SDavid Chisnall __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a); 10887a984708SDavid Chisnall __v.__construct_at_end(__n); 10897a984708SDavid Chisnall __swap_out_circular_buffer(__v); 10907a984708SDavid Chisnall } 10917a984708SDavid Chisnall} 10927a984708SDavid Chisnall 10937a984708SDavid Chisnall// Default constructs __n objects starting at __end_ 10947a984708SDavid Chisnall// throws if construction throws 10957a984708SDavid Chisnall// Postcondition: size() == size() + __n 10967a984708SDavid Chisnall// Exception safety: strong. 10977a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 10987a984708SDavid Chisnallvoid 10997a984708SDavid Chisnallvector<_Tp, _Allocator>::__append(size_type __n, const_reference __x) 11007a984708SDavid Chisnall{ 11017a984708SDavid Chisnall if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n) 11027a984708SDavid Chisnall this->__construct_at_end(__n, __x); 11037a984708SDavid Chisnall else 11047a984708SDavid Chisnall { 11057a984708SDavid Chisnall allocator_type& __a = this->__alloc(); 11067a984708SDavid Chisnall __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a); 11077a984708SDavid Chisnall __v.__construct_at_end(__n, __x); 11087a984708SDavid Chisnall __swap_out_circular_buffer(__v); 11097a984708SDavid Chisnall } 11107a984708SDavid Chisnall} 11117a984708SDavid Chisnall 11127a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 11137a984708SDavid Chisnallvector<_Tp, _Allocator>::vector(size_type __n) 11147a984708SDavid Chisnall{ 11157a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2 11167a984708SDavid Chisnall __get_db()->__insert_c(this); 11177a984708SDavid Chisnall#endif 11187a984708SDavid Chisnall if (__n > 0) 11197a984708SDavid Chisnall { 11204ba319b5SDimitry Andric __vallocate(__n); 11217a984708SDavid Chisnall __construct_at_end(__n); 11227a984708SDavid Chisnall } 11237a984708SDavid Chisnall} 11247a984708SDavid Chisnall 11254f7ab58eSDimitry Andric#if _LIBCPP_STD_VER > 11 11264f7ab58eSDimitry Andrictemplate <class _Tp, class _Allocator> 11274f7ab58eSDimitry Andricvector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a) 11284f7ab58eSDimitry Andric : __base(__a) 11294f7ab58eSDimitry Andric{ 11304f7ab58eSDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 11314f7ab58eSDimitry Andric __get_db()->__insert_c(this); 11324f7ab58eSDimitry Andric#endif 11334f7ab58eSDimitry Andric if (__n > 0) 11344f7ab58eSDimitry Andric { 11354ba319b5SDimitry Andric __vallocate(__n); 11364f7ab58eSDimitry Andric __construct_at_end(__n); 11374f7ab58eSDimitry Andric } 11384f7ab58eSDimitry Andric} 11394f7ab58eSDimitry Andric#endif 11404f7ab58eSDimitry Andric 11417a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 11424ba319b5SDimitry Andricvector<_Tp, _Allocator>::vector(size_type __n, const value_type& __x) 11437a984708SDavid Chisnall{ 11447a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2 11457a984708SDavid Chisnall __get_db()->__insert_c(this); 11467a984708SDavid Chisnall#endif 11477a984708SDavid Chisnall if (__n > 0) 11487a984708SDavid Chisnall { 11494ba319b5SDimitry Andric __vallocate(__n); 11507a984708SDavid Chisnall __construct_at_end(__n, __x); 11517a984708SDavid Chisnall } 11527a984708SDavid Chisnall} 11537a984708SDavid Chisnall 11547a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 11554ba319b5SDimitry Andricvector<_Tp, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a) 11567a984708SDavid Chisnall : __base(__a) 11577a984708SDavid Chisnall{ 11587a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2 11597a984708SDavid Chisnall __get_db()->__insert_c(this); 11607a984708SDavid Chisnall#endif 11617a984708SDavid Chisnall if (__n > 0) 11627a984708SDavid Chisnall { 11634ba319b5SDimitry Andric __vallocate(__n); 11647a984708SDavid Chisnall __construct_at_end(__n, __x); 11657a984708SDavid Chisnall } 11667a984708SDavid Chisnall} 11677a984708SDavid Chisnall 11687a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 11697a984708SDavid Chisnalltemplate <class _InputIterator> 11704f7ab58eSDimitry Andricvector<_Tp, _Allocator>::vector(_InputIterator __first, 11717a984708SDavid Chisnall typename enable_if<__is_input_iterator <_InputIterator>::value && 11721bf9f7c1SDimitry Andric !__is_forward_iterator<_InputIterator>::value && 11731bf9f7c1SDimitry Andric is_constructible< 11741bf9f7c1SDimitry Andric value_type, 11754f7ab58eSDimitry Andric typename iterator_traits<_InputIterator>::reference>::value, 11764f7ab58eSDimitry Andric _InputIterator>::type __last) 11777a984708SDavid Chisnall{ 11787a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2 11797a984708SDavid Chisnall __get_db()->__insert_c(this); 11807a984708SDavid Chisnall#endif 11817a984708SDavid Chisnall for (; __first != __last; ++__first) 1182d4419f6fSDimitry Andric __emplace_back(*__first); 11837a984708SDavid Chisnall} 11847a984708SDavid Chisnall 11857a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 11867a984708SDavid Chisnalltemplate <class _InputIterator> 11877a984708SDavid Chisnallvector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, 11887a984708SDavid Chisnall typename enable_if<__is_input_iterator <_InputIterator>::value && 11891bf9f7c1SDimitry Andric !__is_forward_iterator<_InputIterator>::value && 11901bf9f7c1SDimitry Andric is_constructible< 11911bf9f7c1SDimitry Andric value_type, 11921bf9f7c1SDimitry Andric typename iterator_traits<_InputIterator>::reference>::value>::type*) 11937a984708SDavid Chisnall : __base(__a) 11947a984708SDavid Chisnall{ 11957a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2 11967a984708SDavid Chisnall __get_db()->__insert_c(this); 11977a984708SDavid Chisnall#endif 11987a984708SDavid Chisnall for (; __first != __last; ++__first) 1199d4419f6fSDimitry Andric __emplace_back(*__first); 12007a984708SDavid Chisnall} 12017a984708SDavid Chisnall 12027a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 12037a984708SDavid Chisnalltemplate <class _ForwardIterator> 12044f7ab58eSDimitry Andricvector<_Tp, _Allocator>::vector(_ForwardIterator __first, 12051bf9f7c1SDimitry Andric typename enable_if<__is_forward_iterator<_ForwardIterator>::value && 12061bf9f7c1SDimitry Andric is_constructible< 12071bf9f7c1SDimitry Andric value_type, 12084f7ab58eSDimitry Andric typename iterator_traits<_ForwardIterator>::reference>::value, 12094f7ab58eSDimitry Andric _ForwardIterator>::type __last) 12107a984708SDavid Chisnall{ 12117a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2 12127a984708SDavid Chisnall __get_db()->__insert_c(this); 12137a984708SDavid Chisnall#endif 12147a984708SDavid Chisnall size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); 12157a984708SDavid Chisnall if (__n > 0) 12167a984708SDavid Chisnall { 12174ba319b5SDimitry Andric __vallocate(__n); 1218854fa44bSDimitry Andric __construct_at_end(__first, __last, __n); 12197a984708SDavid Chisnall } 12207a984708SDavid Chisnall} 12217a984708SDavid Chisnall 12227a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 12237a984708SDavid Chisnalltemplate <class _ForwardIterator> 12247a984708SDavid Chisnallvector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, 12251bf9f7c1SDimitry Andric typename enable_if<__is_forward_iterator<_ForwardIterator>::value && 12261bf9f7c1SDimitry Andric is_constructible< 12271bf9f7c1SDimitry Andric value_type, 12281bf9f7c1SDimitry Andric typename iterator_traits<_ForwardIterator>::reference>::value>::type*) 12297a984708SDavid Chisnall : __base(__a) 12307a984708SDavid Chisnall{ 12317a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2 12327a984708SDavid Chisnall __get_db()->__insert_c(this); 12337a984708SDavid Chisnall#endif 12347a984708SDavid Chisnall size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); 12357a984708SDavid Chisnall if (__n > 0) 12367a984708SDavid Chisnall { 12374ba319b5SDimitry Andric __vallocate(__n); 1238854fa44bSDimitry Andric __construct_at_end(__first, __last, __n); 12397a984708SDavid Chisnall } 12407a984708SDavid Chisnall} 12417a984708SDavid Chisnall 12427a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 12437a984708SDavid Chisnallvector<_Tp, _Allocator>::vector(const vector& __x) 12447a984708SDavid Chisnall : __base(__alloc_traits::select_on_container_copy_construction(__x.__alloc())) 12457a984708SDavid Chisnall{ 12467a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2 12477a984708SDavid Chisnall __get_db()->__insert_c(this); 12487a984708SDavid Chisnall#endif 12497a984708SDavid Chisnall size_type __n = __x.size(); 12507a984708SDavid Chisnall if (__n > 0) 12517a984708SDavid Chisnall { 12524ba319b5SDimitry Andric __vallocate(__n); 1253854fa44bSDimitry Andric __construct_at_end(__x.__begin_, __x.__end_, __n); 12547a984708SDavid Chisnall } 12557a984708SDavid Chisnall} 12567a984708SDavid Chisnall 12577a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 12587a984708SDavid Chisnallvector<_Tp, _Allocator>::vector(const vector& __x, const allocator_type& __a) 12597a984708SDavid Chisnall : __base(__a) 12607a984708SDavid Chisnall{ 12617a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2 12627a984708SDavid Chisnall __get_db()->__insert_c(this); 12637a984708SDavid Chisnall#endif 12647a984708SDavid Chisnall size_type __n = __x.size(); 12657a984708SDavid Chisnall if (__n > 0) 12667a984708SDavid Chisnall { 12674ba319b5SDimitry Andric __vallocate(__n); 1268854fa44bSDimitry Andric __construct_at_end(__x.__begin_, __x.__end_, __n); 12697a984708SDavid Chisnall } 12707a984708SDavid Chisnall} 12717a984708SDavid Chisnall 1272540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG 12737a984708SDavid Chisnall 12747a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 12754f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 12767a984708SDavid Chisnallvector<_Tp, _Allocator>::vector(vector&& __x) 1277854fa44bSDimitry Andric#if _LIBCPP_STD_VER > 14 1278854fa44bSDimitry Andric _NOEXCEPT 1279854fa44bSDimitry Andric#else 12807a984708SDavid Chisnall _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) 1281854fa44bSDimitry Andric#endif 12827a984708SDavid Chisnall : __base(_VSTD::move(__x.__alloc())) 12837a984708SDavid Chisnall{ 12847a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2 12857a984708SDavid Chisnall __get_db()->__insert_c(this); 12867a984708SDavid Chisnall __get_db()->swap(this, &__x); 12877a984708SDavid Chisnall#endif 12887a984708SDavid Chisnall this->__begin_ = __x.__begin_; 12897a984708SDavid Chisnall this->__end_ = __x.__end_; 12907a984708SDavid Chisnall this->__end_cap() = __x.__end_cap(); 12914bab9fd9SDavid Chisnall __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr; 12927a984708SDavid Chisnall} 12937a984708SDavid Chisnall 12947a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 12954f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 12967a984708SDavid Chisnallvector<_Tp, _Allocator>::vector(vector&& __x, const allocator_type& __a) 12977a984708SDavid Chisnall : __base(__a) 12987a984708SDavid Chisnall{ 12997a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2 13007a984708SDavid Chisnall __get_db()->__insert_c(this); 13017a984708SDavid Chisnall#endif 13027a984708SDavid Chisnall if (__a == __x.__alloc()) 13037a984708SDavid Chisnall { 13047a984708SDavid Chisnall this->__begin_ = __x.__begin_; 13057a984708SDavid Chisnall this->__end_ = __x.__end_; 13067a984708SDavid Chisnall this->__end_cap() = __x.__end_cap(); 13077a984708SDavid Chisnall __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr; 13087a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2 13097a984708SDavid Chisnall __get_db()->swap(this, &__x); 13107a984708SDavid Chisnall#endif 13117a984708SDavid Chisnall } 13127a984708SDavid Chisnall else 13137a984708SDavid Chisnall { 131494e3ee44SDavid Chisnall typedef move_iterator<iterator> _Ip; 131594e3ee44SDavid Chisnall assign(_Ip(__x.begin()), _Ip(__x.end())); 13167a984708SDavid Chisnall } 13177a984708SDavid Chisnall} 13187a984708SDavid Chisnall 13197a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 13204f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 13217a984708SDavid Chisnallvector<_Tp, _Allocator>::vector(initializer_list<value_type> __il) 13227a984708SDavid Chisnall{ 13237a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2 13247a984708SDavid Chisnall __get_db()->__insert_c(this); 13257a984708SDavid Chisnall#endif 13267a984708SDavid Chisnall if (__il.size() > 0) 13277a984708SDavid Chisnall { 13284ba319b5SDimitry Andric __vallocate(__il.size()); 1329854fa44bSDimitry Andric __construct_at_end(__il.begin(), __il.end(), __il.size()); 13307a984708SDavid Chisnall } 13317a984708SDavid Chisnall} 13327a984708SDavid Chisnall 13337a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 13344f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 13357a984708SDavid Chisnallvector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a) 13367a984708SDavid Chisnall : __base(__a) 13377a984708SDavid Chisnall{ 13387a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2 13397a984708SDavid Chisnall __get_db()->__insert_c(this); 13407a984708SDavid Chisnall#endif 13417a984708SDavid Chisnall if (__il.size() > 0) 13427a984708SDavid Chisnall { 13434ba319b5SDimitry Andric __vallocate(__il.size()); 1344854fa44bSDimitry Andric __construct_at_end(__il.begin(), __il.end(), __il.size()); 13457a984708SDavid Chisnall } 13467a984708SDavid Chisnall} 13477a984708SDavid Chisnall 13487a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 13494f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 13507a984708SDavid Chisnallvector<_Tp, _Allocator>& 13517a984708SDavid Chisnallvector<_Tp, _Allocator>::operator=(vector&& __x) 13529729cf09SDimitry Andric _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) 13537a984708SDavid Chisnall{ 13547a984708SDavid Chisnall __move_assign(__x, integral_constant<bool, 13557a984708SDavid Chisnall __alloc_traits::propagate_on_container_move_assignment::value>()); 13567a984708SDavid Chisnall return *this; 13577a984708SDavid Chisnall} 13587a984708SDavid Chisnall 13597a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 13607a984708SDavid Chisnallvoid 13617a984708SDavid Chisnallvector<_Tp, _Allocator>::__move_assign(vector& __c, false_type) 13629729cf09SDimitry Andric _NOEXCEPT_(__alloc_traits::is_always_equal::value) 13637a984708SDavid Chisnall{ 13647a984708SDavid Chisnall if (__base::__alloc() != __c.__alloc()) 13657a984708SDavid Chisnall { 136694e3ee44SDavid Chisnall typedef move_iterator<iterator> _Ip; 136794e3ee44SDavid Chisnall assign(_Ip(__c.begin()), _Ip(__c.end())); 13687a984708SDavid Chisnall } 13697a984708SDavid Chisnall else 13707a984708SDavid Chisnall __move_assign(__c, true_type()); 13717a984708SDavid Chisnall} 13727a984708SDavid Chisnall 13737a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 13747a984708SDavid Chisnallvoid 13757a984708SDavid Chisnallvector<_Tp, _Allocator>::__move_assign(vector& __c, true_type) 13767a984708SDavid Chisnall _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) 13777a984708SDavid Chisnall{ 13784ba319b5SDimitry Andric __vdeallocate(); 1379d72607e9SDimitry Andric __base::__move_assign_alloc(__c); // this can throw 13807a984708SDavid Chisnall this->__begin_ = __c.__begin_; 13817a984708SDavid Chisnall this->__end_ = __c.__end_; 13827a984708SDavid Chisnall this->__end_cap() = __c.__end_cap(); 13837a984708SDavid Chisnall __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr; 13847a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2 13857a984708SDavid Chisnall __get_db()->swap(this, &__c); 13867a984708SDavid Chisnall#endif 13877a984708SDavid Chisnall} 13887a984708SDavid Chisnall 1389540d2a8bSDimitry Andric#endif // !_LIBCPP_CXX03_LANG 13907a984708SDavid Chisnall 13917a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 13924f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 13937a984708SDavid Chisnallvector<_Tp, _Allocator>& 13947a984708SDavid Chisnallvector<_Tp, _Allocator>::operator=(const vector& __x) 13957a984708SDavid Chisnall{ 13967a984708SDavid Chisnall if (this != &__x) 13977a984708SDavid Chisnall { 13987a984708SDavid Chisnall __base::__copy_assign_alloc(__x); 13997a984708SDavid Chisnall assign(__x.__begin_, __x.__end_); 14007a984708SDavid Chisnall } 14017a984708SDavid Chisnall return *this; 14027a984708SDavid Chisnall} 14037a984708SDavid Chisnall 14047a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 14057a984708SDavid Chisnalltemplate <class _InputIterator> 14067a984708SDavid Chisnalltypename enable_if 14077a984708SDavid Chisnall< 14087a984708SDavid Chisnall __is_input_iterator <_InputIterator>::value && 14091bf9f7c1SDimitry Andric !__is_forward_iterator<_InputIterator>::value && 14101bf9f7c1SDimitry Andric is_constructible< 14111bf9f7c1SDimitry Andric _Tp, 14121bf9f7c1SDimitry Andric typename iterator_traits<_InputIterator>::reference>::value, 14137a984708SDavid Chisnall void 14147a984708SDavid Chisnall>::type 14157a984708SDavid Chisnallvector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last) 14167a984708SDavid Chisnall{ 14177a984708SDavid Chisnall clear(); 14187a984708SDavid Chisnall for (; __first != __last; ++__first) 1419d4419f6fSDimitry Andric __emplace_back(*__first); 14207a984708SDavid Chisnall} 14217a984708SDavid Chisnall 14227a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 14237a984708SDavid Chisnalltemplate <class _ForwardIterator> 14247a984708SDavid Chisnalltypename enable_if 14257a984708SDavid Chisnall< 14261bf9f7c1SDimitry Andric __is_forward_iterator<_ForwardIterator>::value && 14271bf9f7c1SDimitry Andric is_constructible< 14281bf9f7c1SDimitry Andric _Tp, 14291bf9f7c1SDimitry Andric typename iterator_traits<_ForwardIterator>::reference>::value, 14307a984708SDavid Chisnall void 14317a984708SDavid Chisnall>::type 14327a984708SDavid Chisnallvector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) 14337a984708SDavid Chisnall{ 1434854fa44bSDimitry Andric size_type __new_size = static_cast<size_type>(_VSTD::distance(__first, __last)); 1435854fa44bSDimitry Andric if (__new_size <= capacity()) 14367a984708SDavid Chisnall { 14377a984708SDavid Chisnall _ForwardIterator __mid = __last; 14387a984708SDavid Chisnall bool __growing = false; 1439854fa44bSDimitry Andric if (__new_size > size()) 14407a984708SDavid Chisnall { 14417a984708SDavid Chisnall __growing = true; 14427a984708SDavid Chisnall __mid = __first; 14437a984708SDavid Chisnall _VSTD::advance(__mid, size()); 14447a984708SDavid Chisnall } 14457a984708SDavid Chisnall pointer __m = _VSTD::copy(__first, __mid, this->__begin_); 14467a984708SDavid Chisnall if (__growing) 1447854fa44bSDimitry Andric __construct_at_end(__mid, __last, __new_size - size()); 14487a984708SDavid Chisnall else 14497a984708SDavid Chisnall this->__destruct_at_end(__m); 14507a984708SDavid Chisnall } 14517a984708SDavid Chisnall else 14527a984708SDavid Chisnall { 14534ba319b5SDimitry Andric __vdeallocate(); 14544ba319b5SDimitry Andric __vallocate(__recommend(__new_size)); 1455854fa44bSDimitry Andric __construct_at_end(__first, __last, __new_size); 14567a984708SDavid Chisnall } 1457aed8d94eSDimitry Andric __invalidate_all_iterators(); 14587a984708SDavid Chisnall} 14597a984708SDavid Chisnall 14607a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 14617a984708SDavid Chisnallvoid 14627a984708SDavid Chisnallvector<_Tp, _Allocator>::assign(size_type __n, const_reference __u) 14637a984708SDavid Chisnall{ 14647a984708SDavid Chisnall if (__n <= capacity()) 14657a984708SDavid Chisnall { 14667a984708SDavid Chisnall size_type __s = size(); 14677a984708SDavid Chisnall _VSTD::fill_n(this->__begin_, _VSTD::min(__n, __s), __u); 14687a984708SDavid Chisnall if (__n > __s) 14697a984708SDavid Chisnall __construct_at_end(__n - __s, __u); 14707a984708SDavid Chisnall else 14717a984708SDavid Chisnall this->__destruct_at_end(this->__begin_ + __n); 14727a984708SDavid Chisnall } 14737a984708SDavid Chisnall else 14747a984708SDavid Chisnall { 14754ba319b5SDimitry Andric __vdeallocate(); 14764ba319b5SDimitry Andric __vallocate(__recommend(static_cast<size_type>(__n))); 14777a984708SDavid Chisnall __construct_at_end(__n, __u); 14787a984708SDavid Chisnall } 1479aed8d94eSDimitry Andric __invalidate_all_iterators(); 14807a984708SDavid Chisnall} 14817a984708SDavid Chisnall 14827a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 14834f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 14847a984708SDavid Chisnalltypename vector<_Tp, _Allocator>::iterator 14857a984708SDavid Chisnallvector<_Tp, _Allocator>::__make_iter(pointer __p) _NOEXCEPT 14867a984708SDavid Chisnall{ 14877a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2 14887a984708SDavid Chisnall return iterator(this, __p); 14897a984708SDavid Chisnall#else 14907a984708SDavid Chisnall return iterator(__p); 14917a984708SDavid Chisnall#endif 14927a984708SDavid Chisnall} 14937a984708SDavid Chisnall 14947a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 14954f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 14967a984708SDavid Chisnalltypename vector<_Tp, _Allocator>::const_iterator 14977a984708SDavid Chisnallvector<_Tp, _Allocator>::__make_iter(const_pointer __p) const _NOEXCEPT 14987a984708SDavid Chisnall{ 14997a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2 15007a984708SDavid Chisnall return const_iterator(this, __p); 15017a984708SDavid Chisnall#else 15027a984708SDavid Chisnall return const_iterator(__p); 15037a984708SDavid Chisnall#endif 15047a984708SDavid Chisnall} 15057a984708SDavid Chisnall 15067a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 15074f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 15087a984708SDavid Chisnalltypename vector<_Tp, _Allocator>::iterator 15097a984708SDavid Chisnallvector<_Tp, _Allocator>::begin() _NOEXCEPT 15107a984708SDavid Chisnall{ 15117a984708SDavid Chisnall return __make_iter(this->__begin_); 15127a984708SDavid Chisnall} 15137a984708SDavid Chisnall 15147a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 15154f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 15167a984708SDavid Chisnalltypename vector<_Tp, _Allocator>::const_iterator 15177a984708SDavid Chisnallvector<_Tp, _Allocator>::begin() const _NOEXCEPT 15187a984708SDavid Chisnall{ 15197a984708SDavid Chisnall return __make_iter(this->__begin_); 15207a984708SDavid Chisnall} 15217a984708SDavid Chisnall 15227a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 15234f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 15247a984708SDavid Chisnalltypename vector<_Tp, _Allocator>::iterator 15257a984708SDavid Chisnallvector<_Tp, _Allocator>::end() _NOEXCEPT 15267a984708SDavid Chisnall{ 15277a984708SDavid Chisnall return __make_iter(this->__end_); 15287a984708SDavid Chisnall} 15297a984708SDavid Chisnall 15307a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 15314f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 15327a984708SDavid Chisnalltypename vector<_Tp, _Allocator>::const_iterator 15337a984708SDavid Chisnallvector<_Tp, _Allocator>::end() const _NOEXCEPT 15347a984708SDavid Chisnall{ 15357a984708SDavid Chisnall return __make_iter(this->__end_); 15367a984708SDavid Chisnall} 15377a984708SDavid Chisnall 15387a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 15394f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 15407a984708SDavid Chisnalltypename vector<_Tp, _Allocator>::reference 15417a984708SDavid Chisnallvector<_Tp, _Allocator>::operator[](size_type __n) 15427a984708SDavid Chisnall{ 15437a984708SDavid Chisnall _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds"); 15447a984708SDavid Chisnall return this->__begin_[__n]; 15457a984708SDavid Chisnall} 15467a984708SDavid Chisnall 15477a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 15484f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 15497a984708SDavid Chisnalltypename vector<_Tp, _Allocator>::const_reference 15507a984708SDavid Chisnallvector<_Tp, _Allocator>::operator[](size_type __n) const 15517a984708SDavid Chisnall{ 15527a984708SDavid Chisnall _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds"); 15537a984708SDavid Chisnall return this->__begin_[__n]; 15547a984708SDavid Chisnall} 15557a984708SDavid Chisnall 15567a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 15577a984708SDavid Chisnalltypename vector<_Tp, _Allocator>::reference 15587a984708SDavid Chisnallvector<_Tp, _Allocator>::at(size_type __n) 15597a984708SDavid Chisnall{ 15607a984708SDavid Chisnall if (__n >= size()) 15617a984708SDavid Chisnall this->__throw_out_of_range(); 15627a984708SDavid Chisnall return this->__begin_[__n]; 15637a984708SDavid Chisnall} 15647a984708SDavid Chisnall 15657a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 15667a984708SDavid Chisnalltypename vector<_Tp, _Allocator>::const_reference 15677a984708SDavid Chisnallvector<_Tp, _Allocator>::at(size_type __n) const 15687a984708SDavid Chisnall{ 15697a984708SDavid Chisnall if (__n >= size()) 15707a984708SDavid Chisnall this->__throw_out_of_range(); 15717a984708SDavid Chisnall return this->__begin_[__n]; 15727a984708SDavid Chisnall} 15737a984708SDavid Chisnall 15747a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 15757a984708SDavid Chisnallvoid 15767a984708SDavid Chisnallvector<_Tp, _Allocator>::reserve(size_type __n) 15777a984708SDavid Chisnall{ 15787a984708SDavid Chisnall if (__n > capacity()) 15797a984708SDavid Chisnall { 15807a984708SDavid Chisnall allocator_type& __a = this->__alloc(); 15817a984708SDavid Chisnall __split_buffer<value_type, allocator_type&> __v(__n, size(), __a); 15827a984708SDavid Chisnall __swap_out_circular_buffer(__v); 15837a984708SDavid Chisnall } 15847a984708SDavid Chisnall} 15857a984708SDavid Chisnall 15867a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 15877a984708SDavid Chisnallvoid 15887a984708SDavid Chisnallvector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT 15897a984708SDavid Chisnall{ 15907a984708SDavid Chisnall if (capacity() > size()) 15917a984708SDavid Chisnall { 15927a984708SDavid Chisnall#ifndef _LIBCPP_NO_EXCEPTIONS 15937a984708SDavid Chisnall try 15947a984708SDavid Chisnall { 15957a984708SDavid Chisnall#endif // _LIBCPP_NO_EXCEPTIONS 15967a984708SDavid Chisnall allocator_type& __a = this->__alloc(); 15977a984708SDavid Chisnall __split_buffer<value_type, allocator_type&> __v(size(), size(), __a); 15987a984708SDavid Chisnall __swap_out_circular_buffer(__v); 15997a984708SDavid Chisnall#ifndef _LIBCPP_NO_EXCEPTIONS 16007a984708SDavid Chisnall } 16017a984708SDavid Chisnall catch (...) 16027a984708SDavid Chisnall { 16037a984708SDavid Chisnall } 16047a984708SDavid Chisnall#endif // _LIBCPP_NO_EXCEPTIONS 16057a984708SDavid Chisnall } 16067a984708SDavid Chisnall} 16077a984708SDavid Chisnall 16087a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 160994e3ee44SDavid Chisnalltemplate <class _Up> 161094e3ee44SDavid Chisnallvoid 1611540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG 161294e3ee44SDavid Chisnallvector<_Tp, _Allocator>::__push_back_slow_path(_Up&& __x) 161394e3ee44SDavid Chisnall#else 161494e3ee44SDavid Chisnallvector<_Tp, _Allocator>::__push_back_slow_path(_Up& __x) 161594e3ee44SDavid Chisnall#endif 161694e3ee44SDavid Chisnall{ 161794e3ee44SDavid Chisnall allocator_type& __a = this->__alloc(); 161894e3ee44SDavid Chisnall __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a); 161994e3ee44SDavid Chisnall // __v.push_back(_VSTD::forward<_Up>(__x)); 1620cfdf2879SDavid Chisnall __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(__v.__end_), _VSTD::forward<_Up>(__x)); 1621cfdf2879SDavid Chisnall __v.__end_++; 162294e3ee44SDavid Chisnall __swap_out_circular_buffer(__v); 162394e3ee44SDavid Chisnall} 162494e3ee44SDavid Chisnall 162594e3ee44SDavid Chisnalltemplate <class _Tp, class _Allocator> 16264f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 16277a984708SDavid Chisnallvoid 16287a984708SDavid Chisnallvector<_Tp, _Allocator>::push_back(const_reference __x) 16297a984708SDavid Chisnall{ 163094e3ee44SDavid Chisnall if (this->__end_ != this->__end_cap()) 16317a984708SDavid Chisnall { 1632d72607e9SDimitry Andric __RAII_IncreaseAnnotator __annotator(*this); 16337a984708SDavid Chisnall __alloc_traits::construct(this->__alloc(), 16347a984708SDavid Chisnall _VSTD::__to_raw_pointer(this->__end_), __x); 1635d72607e9SDimitry Andric __annotator.__done(); 16367a984708SDavid Chisnall ++this->__end_; 16377a984708SDavid Chisnall } 16387a984708SDavid Chisnall else 163994e3ee44SDavid Chisnall __push_back_slow_path(__x); 16407a984708SDavid Chisnall} 16417a984708SDavid Chisnall 1642540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG 16437a984708SDavid Chisnall 16447a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 16454f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 16467a984708SDavid Chisnallvoid 16477a984708SDavid Chisnallvector<_Tp, _Allocator>::push_back(value_type&& __x) 16487a984708SDavid Chisnall{ 16497a984708SDavid Chisnall if (this->__end_ < this->__end_cap()) 16507a984708SDavid Chisnall { 1651d72607e9SDimitry Andric __RAII_IncreaseAnnotator __annotator(*this); 16527a984708SDavid Chisnall __alloc_traits::construct(this->__alloc(), 16537a984708SDavid Chisnall _VSTD::__to_raw_pointer(this->__end_), 16547a984708SDavid Chisnall _VSTD::move(__x)); 1655d72607e9SDimitry Andric __annotator.__done(); 16567a984708SDavid Chisnall ++this->__end_; 16577a984708SDavid Chisnall } 16587a984708SDavid Chisnall else 165994e3ee44SDavid Chisnall __push_back_slow_path(_VSTD::move(__x)); 16607a984708SDavid Chisnall} 16617a984708SDavid Chisnall 16627a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 16637a984708SDavid Chisnalltemplate <class... _Args> 16647a984708SDavid Chisnallvoid 166594e3ee44SDavid Chisnallvector<_Tp, _Allocator>::__emplace_back_slow_path(_Args&&... __args) 166694e3ee44SDavid Chisnall{ 166794e3ee44SDavid Chisnall allocator_type& __a = this->__alloc(); 166894e3ee44SDavid Chisnall __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a); 166994e3ee44SDavid Chisnall// __v.emplace_back(_VSTD::forward<_Args>(__args)...); 1670cfdf2879SDavid Chisnall __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(__v.__end_), _VSTD::forward<_Args>(__args)...); 1671cfdf2879SDavid Chisnall __v.__end_++; 167294e3ee44SDavid Chisnall __swap_out_circular_buffer(__v); 167394e3ee44SDavid Chisnall} 167494e3ee44SDavid Chisnall 167594e3ee44SDavid Chisnalltemplate <class _Tp, class _Allocator> 167694e3ee44SDavid Chisnalltemplate <class... _Args> 16779729cf09SDimitry Andricinline 167898221d2eSDimitry Andric#if _LIBCPP_STD_VER > 14 1679aed8d94eSDimitry Andrictypename vector<_Tp, _Allocator>::reference 168098221d2eSDimitry Andric#else 168198221d2eSDimitry Andricvoid 168298221d2eSDimitry Andric#endif 16837a984708SDavid Chisnallvector<_Tp, _Allocator>::emplace_back(_Args&&... __args) 16847a984708SDavid Chisnall{ 16857a984708SDavid Chisnall if (this->__end_ < this->__end_cap()) 16867a984708SDavid Chisnall { 1687d72607e9SDimitry Andric __RAII_IncreaseAnnotator __annotator(*this); 16887a984708SDavid Chisnall __alloc_traits::construct(this->__alloc(), 16897a984708SDavid Chisnall _VSTD::__to_raw_pointer(this->__end_), 16907a984708SDavid Chisnall _VSTD::forward<_Args>(__args)...); 1691d72607e9SDimitry Andric __annotator.__done(); 16927a984708SDavid Chisnall ++this->__end_; 16937a984708SDavid Chisnall } 16947a984708SDavid Chisnall else 169594e3ee44SDavid Chisnall __emplace_back_slow_path(_VSTD::forward<_Args>(__args)...); 169698221d2eSDimitry Andric#if _LIBCPP_STD_VER > 14 1697aed8d94eSDimitry Andric return this->back(); 169898221d2eSDimitry Andric#endif 16997a984708SDavid Chisnall} 17007a984708SDavid Chisnall 1701540d2a8bSDimitry Andric#endif // !_LIBCPP_CXX03_LANG 17027a984708SDavid Chisnall 17037a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 17049729cf09SDimitry Andricinline 17057a984708SDavid Chisnallvoid 17067a984708SDavid Chisnallvector<_Tp, _Allocator>::pop_back() 17077a984708SDavid Chisnall{ 17087a984708SDavid Chisnall _LIBCPP_ASSERT(!empty(), "vector::pop_back called for empty vector"); 17097a984708SDavid Chisnall this->__destruct_at_end(this->__end_ - 1); 17107a984708SDavid Chisnall} 17117a984708SDavid Chisnall 17127a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 17134f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 17147a984708SDavid Chisnalltypename vector<_Tp, _Allocator>::iterator 17157a984708SDavid Chisnallvector<_Tp, _Allocator>::erase(const_iterator __position) 17167a984708SDavid Chisnall{ 17177a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2 17187a984708SDavid Chisnall _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, 17197a984708SDavid Chisnall "vector::erase(iterator) called with an iterator not" 17207a984708SDavid Chisnall " referring to this vector"); 17217a984708SDavid Chisnall#endif 17221bf9f7c1SDimitry Andric _LIBCPP_ASSERT(__position != end(), 17231bf9f7c1SDimitry Andric "vector::erase(iterator) called with a non-dereferenceable iterator"); 17244bab9fd9SDavid Chisnall difference_type __ps = __position - cbegin(); 17254bab9fd9SDavid Chisnall pointer __p = this->__begin_ + __ps; 17267a984708SDavid Chisnall this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p)); 1727aed8d94eSDimitry Andric this->__invalidate_iterators_past(__p-1); 1728aed8d94eSDimitry Andric iterator __r = __make_iter(__p); 17297a984708SDavid Chisnall return __r; 17307a984708SDavid Chisnall} 17317a984708SDavid Chisnall 17327a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 17337a984708SDavid Chisnalltypename vector<_Tp, _Allocator>::iterator 17347a984708SDavid Chisnallvector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last) 17357a984708SDavid Chisnall{ 17367a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2 17377a984708SDavid Chisnall _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this, 17387a984708SDavid Chisnall "vector::erase(iterator, iterator) called with an iterator not" 17397a984708SDavid Chisnall " referring to this vector"); 1740aed8d94eSDimitry Andric _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__last) == this, 1741aed8d94eSDimitry Andric "vector::erase(iterator, iterator) called with an iterator not" 1742aed8d94eSDimitry Andric " referring to this vector"); 17437a984708SDavid Chisnall#endif 17447a984708SDavid Chisnall _LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range"); 17457a984708SDavid Chisnall pointer __p = this->__begin_ + (__first - begin()); 1746aed8d94eSDimitry Andric if (__first != __last) { 17477a984708SDavid Chisnall this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p)); 1748aed8d94eSDimitry Andric this->__invalidate_iterators_past(__p - 1); 1749aed8d94eSDimitry Andric } 1750aed8d94eSDimitry Andric iterator __r = __make_iter(__p); 17517a984708SDavid Chisnall return __r; 17527a984708SDavid Chisnall} 17537a984708SDavid Chisnall 17547a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 17557a984708SDavid Chisnallvoid 17567a984708SDavid Chisnallvector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to) 17577a984708SDavid Chisnall{ 17587a984708SDavid Chisnall pointer __old_last = this->__end_; 17597a984708SDavid Chisnall difference_type __n = __old_last - __to; 17607a984708SDavid Chisnall for (pointer __i = __from_s + __n; __i < __from_e; ++__i, ++this->__end_) 17617a984708SDavid Chisnall __alloc_traits::construct(this->__alloc(), 17627a984708SDavid Chisnall _VSTD::__to_raw_pointer(this->__end_), 17637a984708SDavid Chisnall _VSTD::move(*__i)); 17647a984708SDavid Chisnall _VSTD::move_backward(__from_s, __from_s + __n, __old_last); 17657a984708SDavid Chisnall} 17667a984708SDavid Chisnall 17677a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 17687a984708SDavid Chisnalltypename vector<_Tp, _Allocator>::iterator 17697a984708SDavid Chisnallvector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x) 17707a984708SDavid Chisnall{ 17717a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2 17727a984708SDavid Chisnall _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, 17737a984708SDavid Chisnall "vector::insert(iterator, x) called with an iterator not" 17747a984708SDavid Chisnall " referring to this vector"); 17757a984708SDavid Chisnall#endif 17767a984708SDavid Chisnall pointer __p = this->__begin_ + (__position - begin()); 17777a984708SDavid Chisnall if (this->__end_ < this->__end_cap()) 17787a984708SDavid Chisnall { 1779d72607e9SDimitry Andric __RAII_IncreaseAnnotator __annotator(*this); 17807a984708SDavid Chisnall if (__p == this->__end_) 17817a984708SDavid Chisnall { 17827a984708SDavid Chisnall __alloc_traits::construct(this->__alloc(), 17837a984708SDavid Chisnall _VSTD::__to_raw_pointer(this->__end_), __x); 17847a984708SDavid Chisnall ++this->__end_; 17857a984708SDavid Chisnall } 17867a984708SDavid Chisnall else 17877a984708SDavid Chisnall { 17887a984708SDavid Chisnall __move_range(__p, this->__end_, __p + 1); 17897a984708SDavid Chisnall const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x); 17907a984708SDavid Chisnall if (__p <= __xr && __xr < this->__end_) 17917a984708SDavid Chisnall ++__xr; 17927a984708SDavid Chisnall *__p = *__xr; 17937a984708SDavid Chisnall } 1794d72607e9SDimitry Andric __annotator.__done(); 17957a984708SDavid Chisnall } 17967a984708SDavid Chisnall else 17977a984708SDavid Chisnall { 17987a984708SDavid Chisnall allocator_type& __a = this->__alloc(); 17997a984708SDavid Chisnall __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a); 18007a984708SDavid Chisnall __v.push_back(__x); 18017a984708SDavid Chisnall __p = __swap_out_circular_buffer(__v, __p); 18027a984708SDavid Chisnall } 18037a984708SDavid Chisnall return __make_iter(__p); 18047a984708SDavid Chisnall} 18057a984708SDavid Chisnall 1806540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG 18077a984708SDavid Chisnall 18087a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 18097a984708SDavid Chisnalltypename vector<_Tp, _Allocator>::iterator 18107a984708SDavid Chisnallvector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x) 18117a984708SDavid Chisnall{ 18127a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2 18137a984708SDavid Chisnall _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, 18147a984708SDavid Chisnall "vector::insert(iterator, x) called with an iterator not" 18157a984708SDavid Chisnall " referring to this vector"); 18167a984708SDavid Chisnall#endif 18177a984708SDavid Chisnall pointer __p = this->__begin_ + (__position - begin()); 18187a984708SDavid Chisnall if (this->__end_ < this->__end_cap()) 18197a984708SDavid Chisnall { 1820d72607e9SDimitry Andric __RAII_IncreaseAnnotator __annotator(*this); 18217a984708SDavid Chisnall if (__p == this->__end_) 18227a984708SDavid Chisnall { 18237a984708SDavid Chisnall __alloc_traits::construct(this->__alloc(), 18247a984708SDavid Chisnall _VSTD::__to_raw_pointer(this->__end_), 18257a984708SDavid Chisnall _VSTD::move(__x)); 18267a984708SDavid Chisnall ++this->__end_; 18277a984708SDavid Chisnall } 18287a984708SDavid Chisnall else 18297a984708SDavid Chisnall { 18307a984708SDavid Chisnall __move_range(__p, this->__end_, __p + 1); 18317a984708SDavid Chisnall *__p = _VSTD::move(__x); 18327a984708SDavid Chisnall } 1833d72607e9SDimitry Andric __annotator.__done(); 18347a984708SDavid Chisnall } 18357a984708SDavid Chisnall else 18367a984708SDavid Chisnall { 18377a984708SDavid Chisnall allocator_type& __a = this->__alloc(); 18387a984708SDavid Chisnall __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a); 18397a984708SDavid Chisnall __v.push_back(_VSTD::move(__x)); 18407a984708SDavid Chisnall __p = __swap_out_circular_buffer(__v, __p); 18417a984708SDavid Chisnall } 18427a984708SDavid Chisnall return __make_iter(__p); 18437a984708SDavid Chisnall} 18447a984708SDavid Chisnall 18457a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 18467a984708SDavid Chisnalltemplate <class... _Args> 18477a984708SDavid Chisnalltypename vector<_Tp, _Allocator>::iterator 18487a984708SDavid Chisnallvector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args) 18497a984708SDavid Chisnall{ 18507a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2 18517a984708SDavid Chisnall _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, 18527a984708SDavid Chisnall "vector::emplace(iterator, x) called with an iterator not" 18537a984708SDavid Chisnall " referring to this vector"); 18547a984708SDavid Chisnall#endif 18557a984708SDavid Chisnall pointer __p = this->__begin_ + (__position - begin()); 18567a984708SDavid Chisnall if (this->__end_ < this->__end_cap()) 18577a984708SDavid Chisnall { 1858d72607e9SDimitry Andric __RAII_IncreaseAnnotator __annotator(*this); 18597a984708SDavid Chisnall if (__p == this->__end_) 18607a984708SDavid Chisnall { 18617a984708SDavid Chisnall __alloc_traits::construct(this->__alloc(), 18627a984708SDavid Chisnall _VSTD::__to_raw_pointer(this->__end_), 18637a984708SDavid Chisnall _VSTD::forward<_Args>(__args)...); 18647a984708SDavid Chisnall ++this->__end_; 18657a984708SDavid Chisnall } 18667a984708SDavid Chisnall else 18677a984708SDavid Chisnall { 18687c82a1ecSDimitry Andric __temp_value<value_type, _Allocator> __tmp(this->__alloc(), _VSTD::forward<_Args>(__args)...); 18697a984708SDavid Chisnall __move_range(__p, this->__end_, __p + 1); 18707c82a1ecSDimitry Andric *__p = _VSTD::move(__tmp.get()); 18717a984708SDavid Chisnall } 1872d72607e9SDimitry Andric __annotator.__done(); 18737a984708SDavid Chisnall } 18747a984708SDavid Chisnall else 18757a984708SDavid Chisnall { 18767a984708SDavid Chisnall allocator_type& __a = this->__alloc(); 18777a984708SDavid Chisnall __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a); 18787a984708SDavid Chisnall __v.emplace_back(_VSTD::forward<_Args>(__args)...); 18797a984708SDavid Chisnall __p = __swap_out_circular_buffer(__v, __p); 18807a984708SDavid Chisnall } 18817a984708SDavid Chisnall return __make_iter(__p); 18827a984708SDavid Chisnall} 18837a984708SDavid Chisnall 1884540d2a8bSDimitry Andric#endif // !_LIBCPP_CXX03_LANG 18857a984708SDavid Chisnall 18867a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 18877a984708SDavid Chisnalltypename vector<_Tp, _Allocator>::iterator 18887a984708SDavid Chisnallvector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x) 18897a984708SDavid Chisnall{ 18907a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2 18917a984708SDavid Chisnall _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, 18927a984708SDavid Chisnall "vector::insert(iterator, n, x) called with an iterator not" 18937a984708SDavid Chisnall " referring to this vector"); 18947a984708SDavid Chisnall#endif 18957a984708SDavid Chisnall pointer __p = this->__begin_ + (__position - begin()); 18967a984708SDavid Chisnall if (__n > 0) 18977a984708SDavid Chisnall { 18987a984708SDavid Chisnall if (__n <= static_cast<size_type>(this->__end_cap() - this->__end_)) 18997a984708SDavid Chisnall { 19007a984708SDavid Chisnall size_type __old_n = __n; 19017a984708SDavid Chisnall pointer __old_last = this->__end_; 19027a984708SDavid Chisnall if (__n > static_cast<size_type>(this->__end_ - __p)) 19037a984708SDavid Chisnall { 19047a984708SDavid Chisnall size_type __cx = __n - (this->__end_ - __p); 19057a984708SDavid Chisnall __construct_at_end(__cx, __x); 19067a984708SDavid Chisnall __n -= __cx; 19077a984708SDavid Chisnall } 19087a984708SDavid Chisnall if (__n > 0) 19097a984708SDavid Chisnall { 1910d72607e9SDimitry Andric __RAII_IncreaseAnnotator __annotator(*this, __n); 19117a984708SDavid Chisnall __move_range(__p, __old_last, __p + __old_n); 1912d72607e9SDimitry Andric __annotator.__done(); 19137a984708SDavid Chisnall const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x); 19147a984708SDavid Chisnall if (__p <= __xr && __xr < this->__end_) 19157a984708SDavid Chisnall __xr += __old_n; 19167a984708SDavid Chisnall _VSTD::fill_n(__p, __n, *__xr); 19177a984708SDavid Chisnall } 19187a984708SDavid Chisnall } 19197a984708SDavid Chisnall else 19207a984708SDavid Chisnall { 19217a984708SDavid Chisnall allocator_type& __a = this->__alloc(); 19227a984708SDavid Chisnall __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a); 19237a984708SDavid Chisnall __v.__construct_at_end(__n, __x); 19247a984708SDavid Chisnall __p = __swap_out_circular_buffer(__v, __p); 19257a984708SDavid Chisnall } 19267a984708SDavid Chisnall } 19277a984708SDavid Chisnall return __make_iter(__p); 19287a984708SDavid Chisnall} 19297a984708SDavid Chisnall 19307a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 19317a984708SDavid Chisnalltemplate <class _InputIterator> 19327a984708SDavid Chisnalltypename enable_if 19337a984708SDavid Chisnall< 19347a984708SDavid Chisnall __is_input_iterator <_InputIterator>::value && 19351bf9f7c1SDimitry Andric !__is_forward_iterator<_InputIterator>::value && 19361bf9f7c1SDimitry Andric is_constructible< 19371bf9f7c1SDimitry Andric _Tp, 19381bf9f7c1SDimitry Andric typename iterator_traits<_InputIterator>::reference>::value, 19397a984708SDavid Chisnall typename vector<_Tp, _Allocator>::iterator 19407a984708SDavid Chisnall>::type 19417a984708SDavid Chisnallvector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last) 19427a984708SDavid Chisnall{ 19437a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2 19447a984708SDavid Chisnall _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, 19457a984708SDavid Chisnall "vector::insert(iterator, range) called with an iterator not" 19467a984708SDavid Chisnall " referring to this vector"); 19477a984708SDavid Chisnall#endif 19487a984708SDavid Chisnall difference_type __off = __position - begin(); 19497a984708SDavid Chisnall pointer __p = this->__begin_ + __off; 19507a984708SDavid Chisnall allocator_type& __a = this->__alloc(); 19517a984708SDavid Chisnall pointer __old_last = this->__end_; 19527a984708SDavid Chisnall for (; this->__end_ != this->__end_cap() && __first != __last; ++__first) 19537a984708SDavid Chisnall { 19549729cf09SDimitry Andric __RAII_IncreaseAnnotator __annotator(*this); 19557a984708SDavid Chisnall __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), 19567a984708SDavid Chisnall *__first); 19577a984708SDavid Chisnall ++this->__end_; 19589729cf09SDimitry Andric __annotator.__done(); 19597a984708SDavid Chisnall } 19607a984708SDavid Chisnall __split_buffer<value_type, allocator_type&> __v(__a); 19617a984708SDavid Chisnall if (__first != __last) 19627a984708SDavid Chisnall { 19637a984708SDavid Chisnall#ifndef _LIBCPP_NO_EXCEPTIONS 19647a984708SDavid Chisnall try 19657a984708SDavid Chisnall { 19667a984708SDavid Chisnall#endif // _LIBCPP_NO_EXCEPTIONS 19677a984708SDavid Chisnall __v.__construct_at_end(__first, __last); 19687a984708SDavid Chisnall difference_type __old_size = __old_last - this->__begin_; 19697a984708SDavid Chisnall difference_type __old_p = __p - this->__begin_; 19707a984708SDavid Chisnall reserve(__recommend(size() + __v.size())); 19717a984708SDavid Chisnall __p = this->__begin_ + __old_p; 19727a984708SDavid Chisnall __old_last = this->__begin_ + __old_size; 19737a984708SDavid Chisnall#ifndef _LIBCPP_NO_EXCEPTIONS 19747a984708SDavid Chisnall } 19757a984708SDavid Chisnall catch (...) 19767a984708SDavid Chisnall { 19777a984708SDavid Chisnall erase(__make_iter(__old_last), end()); 19787a984708SDavid Chisnall throw; 19797a984708SDavid Chisnall } 19807a984708SDavid Chisnall#endif // _LIBCPP_NO_EXCEPTIONS 19817a984708SDavid Chisnall } 19827a984708SDavid Chisnall __p = _VSTD::rotate(__p, __old_last, this->__end_); 19837a984708SDavid Chisnall insert(__make_iter(__p), make_move_iterator(__v.begin()), 19847a984708SDavid Chisnall make_move_iterator(__v.end())); 19857a984708SDavid Chisnall return begin() + __off; 19867a984708SDavid Chisnall} 19877a984708SDavid Chisnall 19887a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 19897a984708SDavid Chisnalltemplate <class _ForwardIterator> 19907a984708SDavid Chisnalltypename enable_if 19917a984708SDavid Chisnall< 19921bf9f7c1SDimitry Andric __is_forward_iterator<_ForwardIterator>::value && 19931bf9f7c1SDimitry Andric is_constructible< 19941bf9f7c1SDimitry Andric _Tp, 19951bf9f7c1SDimitry Andric typename iterator_traits<_ForwardIterator>::reference>::value, 19967a984708SDavid Chisnall typename vector<_Tp, _Allocator>::iterator 19977a984708SDavid Chisnall>::type 19987a984708SDavid Chisnallvector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last) 19997a984708SDavid Chisnall{ 20007a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2 20017a984708SDavid Chisnall _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, 20027a984708SDavid Chisnall "vector::insert(iterator, range) called with an iterator not" 20037a984708SDavid Chisnall " referring to this vector"); 20047a984708SDavid Chisnall#endif 20057a984708SDavid Chisnall pointer __p = this->__begin_ + (__position - begin()); 20067a984708SDavid Chisnall difference_type __n = _VSTD::distance(__first, __last); 20077a984708SDavid Chisnall if (__n > 0) 20087a984708SDavid Chisnall { 20097a984708SDavid Chisnall if (__n <= this->__end_cap() - this->__end_) 20107a984708SDavid Chisnall { 20117a984708SDavid Chisnall size_type __old_n = __n; 20127a984708SDavid Chisnall pointer __old_last = this->__end_; 20137a984708SDavid Chisnall _ForwardIterator __m = __last; 20147a984708SDavid Chisnall difference_type __dx = this->__end_ - __p; 20157a984708SDavid Chisnall if (__n > __dx) 20167a984708SDavid Chisnall { 20177a984708SDavid Chisnall __m = __first; 2018854fa44bSDimitry Andric difference_type __diff = this->__end_ - __p; 2019854fa44bSDimitry Andric _VSTD::advance(__m, __diff); 2020854fa44bSDimitry Andric __construct_at_end(__m, __last, __n - __diff); 20217a984708SDavid Chisnall __n = __dx; 20227a984708SDavid Chisnall } 20237a984708SDavid Chisnall if (__n > 0) 20247a984708SDavid Chisnall { 2025d72607e9SDimitry Andric __RAII_IncreaseAnnotator __annotator(*this, __n); 20267a984708SDavid Chisnall __move_range(__p, __old_last, __p + __old_n); 2027d72607e9SDimitry Andric __annotator.__done(); 20287a984708SDavid Chisnall _VSTD::copy(__first, __m, __p); 20297a984708SDavid Chisnall } 20307a984708SDavid Chisnall } 20317a984708SDavid Chisnall else 20327a984708SDavid Chisnall { 20337a984708SDavid Chisnall allocator_type& __a = this->__alloc(); 20347a984708SDavid Chisnall __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a); 20357a984708SDavid Chisnall __v.__construct_at_end(__first, __last); 20367a984708SDavid Chisnall __p = __swap_out_circular_buffer(__v, __p); 20377a984708SDavid Chisnall } 20387a984708SDavid Chisnall } 20397a984708SDavid Chisnall return __make_iter(__p); 20407a984708SDavid Chisnall} 20417a984708SDavid Chisnall 20427a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 20437a984708SDavid Chisnallvoid 20447a984708SDavid Chisnallvector<_Tp, _Allocator>::resize(size_type __sz) 20457a984708SDavid Chisnall{ 20467a984708SDavid Chisnall size_type __cs = size(); 20477a984708SDavid Chisnall if (__cs < __sz) 20487a984708SDavid Chisnall this->__append(__sz - __cs); 20497a984708SDavid Chisnall else if (__cs > __sz) 20507a984708SDavid Chisnall this->__destruct_at_end(this->__begin_ + __sz); 20517a984708SDavid Chisnall} 20527a984708SDavid Chisnall 20537a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 20547a984708SDavid Chisnallvoid 20557a984708SDavid Chisnallvector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x) 20567a984708SDavid Chisnall{ 20577a984708SDavid Chisnall size_type __cs = size(); 20587a984708SDavid Chisnall if (__cs < __sz) 20597a984708SDavid Chisnall this->__append(__sz - __cs, __x); 20607a984708SDavid Chisnall else if (__cs > __sz) 20617a984708SDavid Chisnall this->__destruct_at_end(this->__begin_ + __sz); 20627a984708SDavid Chisnall} 20637a984708SDavid Chisnall 20647a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 20657a984708SDavid Chisnallvoid 20667a984708SDavid Chisnallvector<_Tp, _Allocator>::swap(vector& __x) 2067854fa44bSDimitry Andric#if _LIBCPP_STD_VER >= 14 2068aed8d94eSDimitry Andric _NOEXCEPT_DEBUG 2069854fa44bSDimitry Andric#else 2070aed8d94eSDimitry Andric _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value || 20717a984708SDavid Chisnall __is_nothrow_swappable<allocator_type>::value) 2072854fa44bSDimitry Andric#endif 20737a984708SDavid Chisnall{ 20747a984708SDavid Chisnall _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value || 20757a984708SDavid Chisnall this->__alloc() == __x.__alloc(), 20767a984708SDavid Chisnall "vector::swap: Either propagate_on_container_swap must be true" 20777a984708SDavid Chisnall " or the allocators must compare equal"); 20787a984708SDavid Chisnall _VSTD::swap(this->__begin_, __x.__begin_); 20797a984708SDavid Chisnall _VSTD::swap(this->__end_, __x.__end_); 20807a984708SDavid Chisnall _VSTD::swap(this->__end_cap(), __x.__end_cap()); 2081854fa44bSDimitry Andric __swap_allocator(this->__alloc(), __x.__alloc(), 2082854fa44bSDimitry Andric integral_constant<bool,__alloc_traits::propagate_on_container_swap::value>()); 20837a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2 20847a984708SDavid Chisnall __get_db()->swap(this, &__x); 20857a984708SDavid Chisnall#endif // _LIBCPP_DEBUG_LEVEL >= 2 20867a984708SDavid Chisnall} 20877a984708SDavid Chisnall 20887a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 20897a984708SDavid Chisnallbool 20907a984708SDavid Chisnallvector<_Tp, _Allocator>::__invariants() const 20917a984708SDavid Chisnall{ 20924bab9fd9SDavid Chisnall if (this->__begin_ == nullptr) 20937a984708SDavid Chisnall { 20944bab9fd9SDavid Chisnall if (this->__end_ != nullptr || this->__end_cap() != nullptr) 20957a984708SDavid Chisnall return false; 20967a984708SDavid Chisnall } 20977a984708SDavid Chisnall else 20987a984708SDavid Chisnall { 20997a984708SDavid Chisnall if (this->__begin_ > this->__end_) 21007a984708SDavid Chisnall return false; 21017a984708SDavid Chisnall if (this->__begin_ == this->__end_cap()) 21027a984708SDavid Chisnall return false; 21037a984708SDavid Chisnall if (this->__end_ > this->__end_cap()) 21047a984708SDavid Chisnall return false; 21057a984708SDavid Chisnall } 21067a984708SDavid Chisnall return true; 21077a984708SDavid Chisnall} 21087a984708SDavid Chisnall 21097a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2 21107a984708SDavid Chisnall 21117a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 21127a984708SDavid Chisnallbool 21137a984708SDavid Chisnallvector<_Tp, _Allocator>::__dereferenceable(const const_iterator* __i) const 21147a984708SDavid Chisnall{ 21157a984708SDavid Chisnall return this->__begin_ <= __i->base() && __i->base() < this->__end_; 21167a984708SDavid Chisnall} 21177a984708SDavid Chisnall 21187a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 21197a984708SDavid Chisnallbool 21207a984708SDavid Chisnallvector<_Tp, _Allocator>::__decrementable(const const_iterator* __i) const 21217a984708SDavid Chisnall{ 21227a984708SDavid Chisnall return this->__begin_ < __i->base() && __i->base() <= this->__end_; 21237a984708SDavid Chisnall} 21247a984708SDavid Chisnall 21257a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 21267a984708SDavid Chisnallbool 21277a984708SDavid Chisnallvector<_Tp, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const 21287a984708SDavid Chisnall{ 21297a984708SDavid Chisnall const_pointer __p = __i->base() + __n; 21307a984708SDavid Chisnall return this->__begin_ <= __p && __p <= this->__end_; 21317a984708SDavid Chisnall} 21327a984708SDavid Chisnall 21337a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 21347a984708SDavid Chisnallbool 21357a984708SDavid Chisnallvector<_Tp, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const 21367a984708SDavid Chisnall{ 21377a984708SDavid Chisnall const_pointer __p = __i->base() + __n; 21387a984708SDavid Chisnall return this->__begin_ <= __p && __p < this->__end_; 21397a984708SDavid Chisnall} 21407a984708SDavid Chisnall 21417a984708SDavid Chisnall#endif // _LIBCPP_DEBUG_LEVEL >= 2 21427a984708SDavid Chisnall 21437a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 21444f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 21457a984708SDavid Chisnallvoid 21467a984708SDavid Chisnallvector<_Tp, _Allocator>::__invalidate_all_iterators() 21477a984708SDavid Chisnall{ 21487a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2 21497a984708SDavid Chisnall __get_db()->__invalidate_all(this); 21507a984708SDavid Chisnall#endif // _LIBCPP_DEBUG_LEVEL >= 2 21517a984708SDavid Chisnall} 21527a984708SDavid Chisnall 2153aed8d94eSDimitry Andric 2154aed8d94eSDimitry Andrictemplate <class _Tp, class _Allocator> 2155aed8d94eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 2156aed8d94eSDimitry Andricvoid 2157aed8d94eSDimitry Andricvector<_Tp, _Allocator>::__invalidate_iterators_past(pointer __new_last) { 2158aed8d94eSDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 2159aed8d94eSDimitry Andric __c_node* __c = __get_db()->__find_c_and_lock(this); 2160aed8d94eSDimitry Andric for (__i_node** __p = __c->end_; __p != __c->beg_; ) { 2161aed8d94eSDimitry Andric --__p; 2162aed8d94eSDimitry Andric const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_); 2163aed8d94eSDimitry Andric if (__i->base() > __new_last) { 2164aed8d94eSDimitry Andric (*__p)->__c_ = nullptr; 2165aed8d94eSDimitry Andric if (--__c->end_ != __p) 2166aed8d94eSDimitry Andric memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); 2167aed8d94eSDimitry Andric } 2168aed8d94eSDimitry Andric } 2169aed8d94eSDimitry Andric __get_db()->unlock(); 2170aed8d94eSDimitry Andric#else 2171aed8d94eSDimitry Andric ((void)__new_last); 2172aed8d94eSDimitry Andric#endif 2173aed8d94eSDimitry Andric} 2174aed8d94eSDimitry Andric 21757a984708SDavid Chisnall// vector<bool> 21767a984708SDavid Chisnall 21777a984708SDavid Chisnalltemplate <class _Allocator> class vector<bool, _Allocator>; 21787a984708SDavid Chisnall 21797a984708SDavid Chisnalltemplate <class _Allocator> struct hash<vector<bool, _Allocator> >; 21807a984708SDavid Chisnall 21817a984708SDavid Chisnalltemplate <class _Allocator> 21827a984708SDavid Chisnallstruct __has_storage_type<vector<bool, _Allocator> > 21837a984708SDavid Chisnall{ 21847a984708SDavid Chisnall static const bool value = true; 21857a984708SDavid Chisnall}; 21867a984708SDavid Chisnall 21877a984708SDavid Chisnalltemplate <class _Allocator> 2188aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS vector<bool, _Allocator> 21897a984708SDavid Chisnall : private __vector_base_common<true> 21907a984708SDavid Chisnall{ 21917a984708SDavid Chisnallpublic: 21927a984708SDavid Chisnall typedef vector __self; 21937a984708SDavid Chisnall typedef bool value_type; 21947a984708SDavid Chisnall typedef _Allocator allocator_type; 21957a984708SDavid Chisnall typedef allocator_traits<allocator_type> __alloc_traits; 21967a984708SDavid Chisnall typedef typename __alloc_traits::size_type size_type; 21977a984708SDavid Chisnall typedef typename __alloc_traits::difference_type difference_type; 2198936e9439SDimitry Andric typedef size_type __storage_type; 21997a984708SDavid Chisnall typedef __bit_iterator<vector, false> pointer; 22007a984708SDavid Chisnall typedef __bit_iterator<vector, true> const_pointer; 22017a984708SDavid Chisnall typedef pointer iterator; 22027a984708SDavid Chisnall typedef const_pointer const_iterator; 22037a984708SDavid Chisnall typedef _VSTD::reverse_iterator<iterator> reverse_iterator; 22047a984708SDavid Chisnall typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; 22057a984708SDavid Chisnall 22067a984708SDavid Chisnallprivate: 2207854fa44bSDimitry Andric typedef typename __rebind_alloc_helper<__alloc_traits, __storage_type>::type __storage_allocator; 22087a984708SDavid Chisnall typedef allocator_traits<__storage_allocator> __storage_traits; 22097a984708SDavid Chisnall typedef typename __storage_traits::pointer __storage_pointer; 22107a984708SDavid Chisnall typedef typename __storage_traits::const_pointer __const_storage_pointer; 22117a984708SDavid Chisnall 22127a984708SDavid Chisnall __storage_pointer __begin_; 22137a984708SDavid Chisnall size_type __size_; 22147a984708SDavid Chisnall __compressed_pair<size_type, __storage_allocator> __cap_alloc_; 22157a984708SDavid Chisnallpublic: 22167a984708SDavid Chisnall typedef __bit_reference<vector> reference; 22177a984708SDavid Chisnall typedef __bit_const_reference<vector> const_reference; 22187a984708SDavid Chisnallprivate: 22197a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 22207a984708SDavid Chisnall size_type& __cap() _NOEXCEPT 22217a984708SDavid Chisnall {return __cap_alloc_.first();} 22227a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 22237a984708SDavid Chisnall const size_type& __cap() const _NOEXCEPT 22247a984708SDavid Chisnall {return __cap_alloc_.first();} 22257a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 22267a984708SDavid Chisnall __storage_allocator& __alloc() _NOEXCEPT 22277a984708SDavid Chisnall {return __cap_alloc_.second();} 22287a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 22297a984708SDavid Chisnall const __storage_allocator& __alloc() const _NOEXCEPT 22307a984708SDavid Chisnall {return __cap_alloc_.second();} 22317a984708SDavid Chisnall 22327a984708SDavid Chisnall static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); 22337a984708SDavid Chisnall 22347a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 22357a984708SDavid Chisnall static size_type __internal_cap_to_external(size_type __n) _NOEXCEPT 22367a984708SDavid Chisnall {return __n * __bits_per_word;} 22377a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 22387a984708SDavid Chisnall static size_type __external_cap_to_internal(size_type __n) _NOEXCEPT 22397a984708SDavid Chisnall {return (__n - 1) / __bits_per_word + 1;} 22407a984708SDavid Chisnall 22417a984708SDavid Chisnallpublic: 22427a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 2243854fa44bSDimitry Andric vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value); 2244854fa44bSDimitry Andric 2245854fa44bSDimitry Andric _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a) 2246854fa44bSDimitry Andric#if _LIBCPP_STD_VER <= 14 2247854fa44bSDimitry Andric _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value); 2248854fa44bSDimitry Andric#else 2249854fa44bSDimitry Andric _NOEXCEPT; 2250854fa44bSDimitry Andric#endif 22517a984708SDavid Chisnall ~vector(); 22527a984708SDavid Chisnall explicit vector(size_type __n); 22534f7ab58eSDimitry Andric#if _LIBCPP_STD_VER > 11 22544f7ab58eSDimitry Andric explicit vector(size_type __n, const allocator_type& __a); 22554f7ab58eSDimitry Andric#endif 22567a984708SDavid Chisnall vector(size_type __n, const value_type& __v); 22577a984708SDavid Chisnall vector(size_type __n, const value_type& __v, const allocator_type& __a); 22587a984708SDavid Chisnall template <class _InputIterator> 22597a984708SDavid Chisnall vector(_InputIterator __first, _InputIterator __last, 22607a984708SDavid Chisnall typename enable_if<__is_input_iterator <_InputIterator>::value && 22617a984708SDavid Chisnall !__is_forward_iterator<_InputIterator>::value>::type* = 0); 22627a984708SDavid Chisnall template <class _InputIterator> 22637a984708SDavid Chisnall vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, 22647a984708SDavid Chisnall typename enable_if<__is_input_iterator <_InputIterator>::value && 22657a984708SDavid Chisnall !__is_forward_iterator<_InputIterator>::value>::type* = 0); 22667a984708SDavid Chisnall template <class _ForwardIterator> 22677a984708SDavid Chisnall vector(_ForwardIterator __first, _ForwardIterator __last, 22687a984708SDavid Chisnall typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0); 22697a984708SDavid Chisnall template <class _ForwardIterator> 22707a984708SDavid Chisnall vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, 22717a984708SDavid Chisnall typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0); 22727a984708SDavid Chisnall 22737a984708SDavid Chisnall vector(const vector& __v); 22747a984708SDavid Chisnall vector(const vector& __v, const allocator_type& __a); 22757a984708SDavid Chisnall vector& operator=(const vector& __v); 2276540d2a8bSDimitry Andric 2277540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG 22787a984708SDavid Chisnall vector(initializer_list<value_type> __il); 22797a984708SDavid Chisnall vector(initializer_list<value_type> __il, const allocator_type& __a); 22807a984708SDavid Chisnall 22817a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 22827a984708SDavid Chisnall vector(vector&& __v) 2283854fa44bSDimitry Andric#if _LIBCPP_STD_VER > 14 2284854fa44bSDimitry Andric _NOEXCEPT; 2285854fa44bSDimitry Andric#else 22867a984708SDavid Chisnall _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); 2287854fa44bSDimitry Andric#endif 22887a984708SDavid Chisnall vector(vector&& __v, const allocator_type& __a); 22897a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 22907a984708SDavid Chisnall vector& operator=(vector&& __v) 22919729cf09SDimitry Andric _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)); 2292540d2a8bSDimitry Andric 22937a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 22947a984708SDavid Chisnall vector& operator=(initializer_list<value_type> __il) 22957a984708SDavid Chisnall {assign(__il.begin(), __il.end()); return *this;} 2296540d2a8bSDimitry Andric 2297540d2a8bSDimitry Andric#endif // !_LIBCPP_CXX03_LANG 22987a984708SDavid Chisnall 22997a984708SDavid Chisnall template <class _InputIterator> 23007a984708SDavid Chisnall typename enable_if 23017a984708SDavid Chisnall < 23027a984708SDavid Chisnall __is_input_iterator<_InputIterator>::value && 23037a984708SDavid Chisnall !__is_forward_iterator<_InputIterator>::value, 23047a984708SDavid Chisnall void 23057a984708SDavid Chisnall >::type 23067a984708SDavid Chisnall assign(_InputIterator __first, _InputIterator __last); 23077a984708SDavid Chisnall template <class _ForwardIterator> 23087a984708SDavid Chisnall typename enable_if 23097a984708SDavid Chisnall < 23107a984708SDavid Chisnall __is_forward_iterator<_ForwardIterator>::value, 23117a984708SDavid Chisnall void 23127a984708SDavid Chisnall >::type 23137a984708SDavid Chisnall assign(_ForwardIterator __first, _ForwardIterator __last); 23147a984708SDavid Chisnall 23157a984708SDavid Chisnall void assign(size_type __n, const value_type& __x); 2316540d2a8bSDimitry Andric 2317540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG 23187a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 23197a984708SDavid Chisnall void assign(initializer_list<value_type> __il) 23207a984708SDavid Chisnall {assign(__il.begin(), __il.end());} 2321540d2a8bSDimitry Andric#endif 23227a984708SDavid Chisnall 23237a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT 23247a984708SDavid Chisnall {return allocator_type(this->__alloc());} 23257a984708SDavid Chisnall 23267a984708SDavid Chisnall size_type max_size() const _NOEXCEPT; 23277a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 23287a984708SDavid Chisnall size_type capacity() const _NOEXCEPT 23297a984708SDavid Chisnall {return __internal_cap_to_external(__cap());} 23307a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 23317a984708SDavid Chisnall size_type size() const _NOEXCEPT 23327a984708SDavid Chisnall {return __size_;} 2333b2c7081bSDimitry Andric _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 23347a984708SDavid Chisnall bool empty() const _NOEXCEPT 23357a984708SDavid Chisnall {return __size_ == 0;} 23367a984708SDavid Chisnall void reserve(size_type __n); 23377a984708SDavid Chisnall void shrink_to_fit() _NOEXCEPT; 23387a984708SDavid Chisnall 23397a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 23407a984708SDavid Chisnall iterator begin() _NOEXCEPT 23417a984708SDavid Chisnall {return __make_iter(0);} 23427a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 23437a984708SDavid Chisnall const_iterator begin() const _NOEXCEPT 23447a984708SDavid Chisnall {return __make_iter(0);} 23457a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 23467a984708SDavid Chisnall iterator end() _NOEXCEPT 23477a984708SDavid Chisnall {return __make_iter(__size_);} 23487a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 23497a984708SDavid Chisnall const_iterator end() const _NOEXCEPT 23507a984708SDavid Chisnall {return __make_iter(__size_);} 23517a984708SDavid Chisnall 23527a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 23537a984708SDavid Chisnall reverse_iterator rbegin() _NOEXCEPT 23547a984708SDavid Chisnall {return reverse_iterator(end());} 23557a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 23567a984708SDavid Chisnall const_reverse_iterator rbegin() const _NOEXCEPT 23577a984708SDavid Chisnall {return const_reverse_iterator(end());} 23587a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 23597a984708SDavid Chisnall reverse_iterator rend() _NOEXCEPT 23607a984708SDavid Chisnall {return reverse_iterator(begin());} 23617a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 23627a984708SDavid Chisnall const_reverse_iterator rend() const _NOEXCEPT 23637a984708SDavid Chisnall {return const_reverse_iterator(begin());} 23647a984708SDavid Chisnall 23657a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 23667a984708SDavid Chisnall const_iterator cbegin() const _NOEXCEPT 23677a984708SDavid Chisnall {return __make_iter(0);} 23687a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 23697a984708SDavid Chisnall const_iterator cend() const _NOEXCEPT 23707a984708SDavid Chisnall {return __make_iter(__size_);} 23717a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 23727a984708SDavid Chisnall const_reverse_iterator crbegin() const _NOEXCEPT 23737a984708SDavid Chisnall {return rbegin();} 23747a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 23757a984708SDavid Chisnall const_reverse_iterator crend() const _NOEXCEPT 23767a984708SDavid Chisnall {return rend();} 23777a984708SDavid Chisnall 23787a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) {return __make_ref(__n);} 23797a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const {return __make_ref(__n);} 23807a984708SDavid Chisnall reference at(size_type __n); 23817a984708SDavid Chisnall const_reference at(size_type __n) const; 23827a984708SDavid Chisnall 23837a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY reference front() {return __make_ref(0);} 23847a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY const_reference front() const {return __make_ref(0);} 23857a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY reference back() {return __make_ref(__size_ - 1);} 23867a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY const_reference back() const {return __make_ref(__size_ - 1);} 23877a984708SDavid Chisnall 23887a984708SDavid Chisnall void push_back(const value_type& __x); 23894f7ab58eSDimitry Andric#if _LIBCPP_STD_VER > 11 23904f7ab58eSDimitry Andric template <class... _Args> 239198221d2eSDimitry Andric#if _LIBCPP_STD_VER > 14 239298221d2eSDimitry Andric _LIBCPP_INLINE_VISIBILITY reference emplace_back(_Args&&... __args) 239398221d2eSDimitry Andric#else 239498221d2eSDimitry Andric _LIBCPP_INLINE_VISIBILITY void emplace_back(_Args&&... __args) 239598221d2eSDimitry Andric#endif 239698221d2eSDimitry Andric { 2397aed8d94eSDimitry Andric push_back ( value_type ( _VSTD::forward<_Args>(__args)... )); 239898221d2eSDimitry Andric#if _LIBCPP_STD_VER > 14 2399aed8d94eSDimitry Andric return this->back(); 240098221d2eSDimitry Andric#endif 2401aed8d94eSDimitry Andric } 24024f7ab58eSDimitry Andric#endif 24034f7ab58eSDimitry Andric 24047a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY void pop_back() {--__size_;} 24057a984708SDavid Chisnall 24064f7ab58eSDimitry Andric#if _LIBCPP_STD_VER > 11 24074f7ab58eSDimitry Andric template <class... _Args> 24084f7ab58eSDimitry Andric _LIBCPP_INLINE_VISIBILITY iterator emplace(const_iterator position, _Args&&... __args) 24094f7ab58eSDimitry Andric { return insert ( position, value_type ( _VSTD::forward<_Args>(__args)... )); } 24104f7ab58eSDimitry Andric#endif 24114f7ab58eSDimitry Andric 24127a984708SDavid Chisnall iterator insert(const_iterator __position, const value_type& __x); 24137a984708SDavid Chisnall iterator insert(const_iterator __position, size_type __n, const value_type& __x); 24147a984708SDavid Chisnall iterator insert(const_iterator __position, size_type __n, const_reference __x); 24157a984708SDavid Chisnall template <class _InputIterator> 24167a984708SDavid Chisnall typename enable_if 24177a984708SDavid Chisnall < 24187a984708SDavid Chisnall __is_input_iterator <_InputIterator>::value && 24197a984708SDavid Chisnall !__is_forward_iterator<_InputIterator>::value, 24207a984708SDavid Chisnall iterator 24217a984708SDavid Chisnall >::type 24227a984708SDavid Chisnall insert(const_iterator __position, _InputIterator __first, _InputIterator __last); 24237a984708SDavid Chisnall template <class _ForwardIterator> 24247a984708SDavid Chisnall typename enable_if 24257a984708SDavid Chisnall < 24267a984708SDavid Chisnall __is_forward_iterator<_ForwardIterator>::value, 24277a984708SDavid Chisnall iterator 24287a984708SDavid Chisnall >::type 24297a984708SDavid Chisnall insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last); 2430540d2a8bSDimitry Andric 2431540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG 24327a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 24337a984708SDavid Chisnall iterator insert(const_iterator __position, initializer_list<value_type> __il) 24347a984708SDavid Chisnall {return insert(__position, __il.begin(), __il.end());} 2435540d2a8bSDimitry Andric#endif 24367a984708SDavid Chisnall 24377a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position); 24387a984708SDavid Chisnall iterator erase(const_iterator __first, const_iterator __last); 24397a984708SDavid Chisnall 24407a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 24417a984708SDavid Chisnall void clear() _NOEXCEPT {__size_ = 0;} 24427a984708SDavid Chisnall 24437a984708SDavid Chisnall void swap(vector&) 2444854fa44bSDimitry Andric#if _LIBCPP_STD_VER >= 14 2445854fa44bSDimitry Andric _NOEXCEPT; 2446854fa44bSDimitry Andric#else 24477a984708SDavid Chisnall _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || 24487a984708SDavid Chisnall __is_nothrow_swappable<allocator_type>::value); 2449854fa44bSDimitry Andric#endif 24507c82a1ecSDimitry Andric static void swap(reference __x, reference __y) _NOEXCEPT { _VSTD::swap(__x, __y); } 24517a984708SDavid Chisnall 24527a984708SDavid Chisnall void resize(size_type __sz, value_type __x = false); 24537a984708SDavid Chisnall void flip() _NOEXCEPT; 24547a984708SDavid Chisnall 24557a984708SDavid Chisnall bool __invariants() const; 24567a984708SDavid Chisnall 24577a984708SDavid Chisnallprivate: 24587a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators(); 24594ba319b5SDimitry Andric void __vallocate(size_type __n); 24604ba319b5SDimitry Andric void __vdeallocate() _NOEXCEPT; 24617a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 24624f7ab58eSDimitry Andric static size_type __align_it(size_type __new_size) _NOEXCEPT 2463*b5893f02SDimitry Andric {return __new_size + (__bits_per_word-1) & ~((size_type)__bits_per_word-1);} 24647a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const; 24657a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY void __construct_at_end(size_type __n, bool __x); 24667a984708SDavid Chisnall template <class _ForwardIterator> 24677a984708SDavid Chisnall typename enable_if 24687a984708SDavid Chisnall < 24697a984708SDavid Chisnall __is_forward_iterator<_ForwardIterator>::value, 24707a984708SDavid Chisnall void 24717a984708SDavid Chisnall >::type 24727a984708SDavid Chisnall __construct_at_end(_ForwardIterator __first, _ForwardIterator __last); 24737a984708SDavid Chisnall void __append(size_type __n, const_reference __x); 24747a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 24757a984708SDavid Chisnall reference __make_ref(size_type __pos) _NOEXCEPT 24767a984708SDavid Chisnall {return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);} 24777a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 24787a984708SDavid Chisnall const_reference __make_ref(size_type __pos) const _NOEXCEPT 24797a984708SDavid Chisnall {return const_reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);} 24807a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 24817a984708SDavid Chisnall iterator __make_iter(size_type __pos) _NOEXCEPT 24827a984708SDavid Chisnall {return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));} 24837a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 24847a984708SDavid Chisnall const_iterator __make_iter(size_type __pos) const _NOEXCEPT 24857a984708SDavid Chisnall {return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));} 24867a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 24877a984708SDavid Chisnall iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT 24884bab9fd9SDavid Chisnall {return begin() + (__p - cbegin());} 24897a984708SDavid Chisnall 24907a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 24917a984708SDavid Chisnall void __copy_assign_alloc(const vector& __v) 24927a984708SDavid Chisnall {__copy_assign_alloc(__v, integral_constant<bool, 24937a984708SDavid Chisnall __storage_traits::propagate_on_container_copy_assignment::value>());} 24947a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 24957a984708SDavid Chisnall void __copy_assign_alloc(const vector& __c, true_type) 24967a984708SDavid Chisnall { 24977a984708SDavid Chisnall if (__alloc() != __c.__alloc()) 24984ba319b5SDimitry Andric __vdeallocate(); 24997a984708SDavid Chisnall __alloc() = __c.__alloc(); 25007a984708SDavid Chisnall } 25017a984708SDavid Chisnall 25027a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 250394e3ee44SDavid Chisnall void __copy_assign_alloc(const vector&, false_type) 25047a984708SDavid Chisnall {} 25057a984708SDavid Chisnall 25067a984708SDavid Chisnall void __move_assign(vector& __c, false_type); 25077a984708SDavid Chisnall void __move_assign(vector& __c, true_type) 25087a984708SDavid Chisnall _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); 25097a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 25107a984708SDavid Chisnall void __move_assign_alloc(vector& __c) 25117a984708SDavid Chisnall _NOEXCEPT_( 25127a984708SDavid Chisnall !__storage_traits::propagate_on_container_move_assignment::value || 25137a984708SDavid Chisnall is_nothrow_move_assignable<allocator_type>::value) 25147a984708SDavid Chisnall {__move_assign_alloc(__c, integral_constant<bool, 25157a984708SDavid Chisnall __storage_traits::propagate_on_container_move_assignment::value>());} 25167a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 25177a984708SDavid Chisnall void __move_assign_alloc(vector& __c, true_type) 25187a984708SDavid Chisnall _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) 25197a984708SDavid Chisnall { 25207a984708SDavid Chisnall __alloc() = _VSTD::move(__c.__alloc()); 25217a984708SDavid Chisnall } 25227a984708SDavid Chisnall 25237a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 252494e3ee44SDavid Chisnall void __move_assign_alloc(vector&, false_type) 25257a984708SDavid Chisnall _NOEXCEPT 25267a984708SDavid Chisnall {} 25277a984708SDavid Chisnall 25287a984708SDavid Chisnall size_t __hash_code() const _NOEXCEPT; 25297a984708SDavid Chisnall 25307a984708SDavid Chisnall friend class __bit_reference<vector>; 25317a984708SDavid Chisnall friend class __bit_const_reference<vector>; 25327a984708SDavid Chisnall friend class __bit_iterator<vector, false>; 25337a984708SDavid Chisnall friend class __bit_iterator<vector, true>; 2534936e9439SDimitry Andric friend struct __bit_array<vector>; 2535aed8d94eSDimitry Andric friend struct _LIBCPP_TEMPLATE_VIS hash<vector>; 25367a984708SDavid Chisnall}; 25377a984708SDavid Chisnall 25387a984708SDavid Chisnalltemplate <class _Allocator> 25394f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 25407a984708SDavid Chisnallvoid 25417a984708SDavid Chisnallvector<bool, _Allocator>::__invalidate_all_iterators() 25427a984708SDavid Chisnall{ 25437a984708SDavid Chisnall} 25447a984708SDavid Chisnall 25457a984708SDavid Chisnall// Allocate space for __n objects 25467a984708SDavid Chisnall// throws length_error if __n > max_size() 25477a984708SDavid Chisnall// throws (probably bad_alloc) if memory run out 25487a984708SDavid Chisnall// Precondition: __begin_ == __end_ == __cap() == 0 25497a984708SDavid Chisnall// Precondition: __n > 0 25507a984708SDavid Chisnall// Postcondition: capacity() == __n 25517a984708SDavid Chisnall// Postcondition: size() == 0 25527a984708SDavid Chisnalltemplate <class _Allocator> 25537a984708SDavid Chisnallvoid 25544ba319b5SDimitry Andricvector<bool, _Allocator>::__vallocate(size_type __n) 25557a984708SDavid Chisnall{ 25567a984708SDavid Chisnall if (__n > max_size()) 25577a984708SDavid Chisnall this->__throw_length_error(); 25587a984708SDavid Chisnall __n = __external_cap_to_internal(__n); 25597a984708SDavid Chisnall this->__begin_ = __storage_traits::allocate(this->__alloc(), __n); 25607a984708SDavid Chisnall this->__size_ = 0; 25617a984708SDavid Chisnall this->__cap() = __n; 25627a984708SDavid Chisnall} 25637a984708SDavid Chisnall 25647a984708SDavid Chisnalltemplate <class _Allocator> 25657a984708SDavid Chisnallvoid 25664ba319b5SDimitry Andricvector<bool, _Allocator>::__vdeallocate() _NOEXCEPT 25677a984708SDavid Chisnall{ 25684bab9fd9SDavid Chisnall if (this->__begin_ != nullptr) 25697a984708SDavid Chisnall { 25707a984708SDavid Chisnall __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap()); 25717a984708SDavid Chisnall __invalidate_all_iterators(); 25724bab9fd9SDavid Chisnall this->__begin_ = nullptr; 25737a984708SDavid Chisnall this->__size_ = this->__cap() = 0; 25747a984708SDavid Chisnall } 25757a984708SDavid Chisnall} 25767a984708SDavid Chisnall 25777a984708SDavid Chisnalltemplate <class _Allocator> 25787a984708SDavid Chisnalltypename vector<bool, _Allocator>::size_type 25797a984708SDavid Chisnallvector<bool, _Allocator>::max_size() const _NOEXCEPT 25807a984708SDavid Chisnall{ 25817a984708SDavid Chisnall size_type __amax = __storage_traits::max_size(__alloc()); 25827a984708SDavid Chisnall size_type __nmax = numeric_limits<size_type>::max() / 2; // end() >= begin(), always 25837a984708SDavid Chisnall if (__nmax / __bits_per_word <= __amax) 25847a984708SDavid Chisnall return __nmax; 25857a984708SDavid Chisnall return __internal_cap_to_external(__amax); 25867a984708SDavid Chisnall} 25877a984708SDavid Chisnall 25887a984708SDavid Chisnall// Precondition: __new_size > capacity() 25897a984708SDavid Chisnalltemplate <class _Allocator> 25904f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 25917a984708SDavid Chisnalltypename vector<bool, _Allocator>::size_type 25927a984708SDavid Chisnallvector<bool, _Allocator>::__recommend(size_type __new_size) const 25937a984708SDavid Chisnall{ 25947a984708SDavid Chisnall const size_type __ms = max_size(); 25957a984708SDavid Chisnall if (__new_size > __ms) 25967a984708SDavid Chisnall this->__throw_length_error(); 25977a984708SDavid Chisnall const size_type __cap = capacity(); 25987a984708SDavid Chisnall if (__cap >= __ms / 2) 25997a984708SDavid Chisnall return __ms; 26004f7ab58eSDimitry Andric return _VSTD::max(2*__cap, __align_it(__new_size)); 26017a984708SDavid Chisnall} 26027a984708SDavid Chisnall 26037a984708SDavid Chisnall// Default constructs __n objects starting at __end_ 26047a984708SDavid Chisnall// Precondition: __n > 0 26057a984708SDavid Chisnall// Precondition: size() + __n <= capacity() 26067a984708SDavid Chisnall// Postcondition: size() == size() + __n 26077a984708SDavid Chisnalltemplate <class _Allocator> 26084f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 26097a984708SDavid Chisnallvoid 26107a984708SDavid Chisnallvector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x) 26117a984708SDavid Chisnall{ 26127a984708SDavid Chisnall size_type __old_size = this->__size_; 26137a984708SDavid Chisnall this->__size_ += __n; 2614*b5893f02SDimitry Andric if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word)) 2615*b5893f02SDimitry Andric { 2616*b5893f02SDimitry Andric if (this->__size_ <= __bits_per_word) 2617*b5893f02SDimitry Andric this->__begin_[0] = __storage_type(0); 2618*b5893f02SDimitry Andric else 2619*b5893f02SDimitry Andric this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0); 2620*b5893f02SDimitry Andric } 26217a984708SDavid Chisnall _VSTD::fill_n(__make_iter(__old_size), __n, __x); 26227a984708SDavid Chisnall} 26237a984708SDavid Chisnall 26247a984708SDavid Chisnalltemplate <class _Allocator> 26257a984708SDavid Chisnalltemplate <class _ForwardIterator> 26267a984708SDavid Chisnalltypename enable_if 26277a984708SDavid Chisnall< 26287a984708SDavid Chisnall __is_forward_iterator<_ForwardIterator>::value, 26297a984708SDavid Chisnall void 26307a984708SDavid Chisnall>::type 26317a984708SDavid Chisnallvector<bool, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last) 26327a984708SDavid Chisnall{ 26337a984708SDavid Chisnall size_type __old_size = this->__size_; 26347a984708SDavid Chisnall this->__size_ += _VSTD::distance(__first, __last); 2635*b5893f02SDimitry Andric if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word)) 2636*b5893f02SDimitry Andric { 2637*b5893f02SDimitry Andric if (this->__size_ <= __bits_per_word) 2638*b5893f02SDimitry Andric this->__begin_[0] = __storage_type(0); 2639*b5893f02SDimitry Andric else 2640*b5893f02SDimitry Andric this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0); 2641*b5893f02SDimitry Andric } 26427a984708SDavid Chisnall _VSTD::copy(__first, __last, __make_iter(__old_size)); 26437a984708SDavid Chisnall} 26447a984708SDavid Chisnall 26457a984708SDavid Chisnalltemplate <class _Allocator> 26464f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 26477a984708SDavid Chisnallvector<bool, _Allocator>::vector() 26487a984708SDavid Chisnall _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) 26494bab9fd9SDavid Chisnall : __begin_(nullptr), 26507a984708SDavid Chisnall __size_(0), 26517a984708SDavid Chisnall __cap_alloc_(0) 26527a984708SDavid Chisnall{ 26537a984708SDavid Chisnall} 26547a984708SDavid Chisnall 26557a984708SDavid Chisnalltemplate <class _Allocator> 26564f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 26577a984708SDavid Chisnallvector<bool, _Allocator>::vector(const allocator_type& __a) 2658854fa44bSDimitry Andric#if _LIBCPP_STD_VER <= 14 2659854fa44bSDimitry Andric _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value) 2660854fa44bSDimitry Andric#else 2661854fa44bSDimitry Andric _NOEXCEPT 2662854fa44bSDimitry Andric#endif 26634bab9fd9SDavid Chisnall : __begin_(nullptr), 26647a984708SDavid Chisnall __size_(0), 26657a984708SDavid Chisnall __cap_alloc_(0, static_cast<__storage_allocator>(__a)) 26667a984708SDavid Chisnall{ 26677a984708SDavid Chisnall} 26687a984708SDavid Chisnall 26697a984708SDavid Chisnalltemplate <class _Allocator> 26707a984708SDavid Chisnallvector<bool, _Allocator>::vector(size_type __n) 26714bab9fd9SDavid Chisnall : __begin_(nullptr), 26727a984708SDavid Chisnall __size_(0), 26737a984708SDavid Chisnall __cap_alloc_(0) 26747a984708SDavid Chisnall{ 26757a984708SDavid Chisnall if (__n > 0) 26767a984708SDavid Chisnall { 26774ba319b5SDimitry Andric __vallocate(__n); 26787a984708SDavid Chisnall __construct_at_end(__n, false); 26797a984708SDavid Chisnall } 26807a984708SDavid Chisnall} 26817a984708SDavid Chisnall 26824f7ab58eSDimitry Andric#if _LIBCPP_STD_VER > 11 26834f7ab58eSDimitry Andrictemplate <class _Allocator> 26844f7ab58eSDimitry Andricvector<bool, _Allocator>::vector(size_type __n, const allocator_type& __a) 26854f7ab58eSDimitry Andric : __begin_(nullptr), 26864f7ab58eSDimitry Andric __size_(0), 26874f7ab58eSDimitry Andric __cap_alloc_(0, static_cast<__storage_allocator>(__a)) 26884f7ab58eSDimitry Andric{ 26894f7ab58eSDimitry Andric if (__n > 0) 26904f7ab58eSDimitry Andric { 26914ba319b5SDimitry Andric __vallocate(__n); 26924f7ab58eSDimitry Andric __construct_at_end(__n, false); 26934f7ab58eSDimitry Andric } 26944f7ab58eSDimitry Andric} 26954f7ab58eSDimitry Andric#endif 26964f7ab58eSDimitry Andric 26977a984708SDavid Chisnalltemplate <class _Allocator> 26987a984708SDavid Chisnallvector<bool, _Allocator>::vector(size_type __n, const value_type& __x) 26994bab9fd9SDavid Chisnall : __begin_(nullptr), 27007a984708SDavid Chisnall __size_(0), 27017a984708SDavid Chisnall __cap_alloc_(0) 27027a984708SDavid Chisnall{ 27037a984708SDavid Chisnall if (__n > 0) 27047a984708SDavid Chisnall { 27054ba319b5SDimitry Andric __vallocate(__n); 27067a984708SDavid Chisnall __construct_at_end(__n, __x); 27077a984708SDavid Chisnall } 27087a984708SDavid Chisnall} 27097a984708SDavid Chisnall 27107a984708SDavid Chisnalltemplate <class _Allocator> 27117a984708SDavid Chisnallvector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a) 27124bab9fd9SDavid Chisnall : __begin_(nullptr), 27137a984708SDavid Chisnall __size_(0), 27147a984708SDavid Chisnall __cap_alloc_(0, static_cast<__storage_allocator>(__a)) 27157a984708SDavid Chisnall{ 27167a984708SDavid Chisnall if (__n > 0) 27177a984708SDavid Chisnall { 27184ba319b5SDimitry Andric __vallocate(__n); 27197a984708SDavid Chisnall __construct_at_end(__n, __x); 27207a984708SDavid Chisnall } 27217a984708SDavid Chisnall} 27227a984708SDavid Chisnall 27237a984708SDavid Chisnalltemplate <class _Allocator> 27247a984708SDavid Chisnalltemplate <class _InputIterator> 27257a984708SDavid Chisnallvector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, 27267a984708SDavid Chisnall typename enable_if<__is_input_iterator <_InputIterator>::value && 27277a984708SDavid Chisnall !__is_forward_iterator<_InputIterator>::value>::type*) 27284bab9fd9SDavid Chisnall : __begin_(nullptr), 27297a984708SDavid Chisnall __size_(0), 27307a984708SDavid Chisnall __cap_alloc_(0) 27317a984708SDavid Chisnall{ 27327a984708SDavid Chisnall#ifndef _LIBCPP_NO_EXCEPTIONS 27337a984708SDavid Chisnall try 27347a984708SDavid Chisnall { 27357a984708SDavid Chisnall#endif // _LIBCPP_NO_EXCEPTIONS 27367a984708SDavid Chisnall for (; __first != __last; ++__first) 27377a984708SDavid Chisnall push_back(*__first); 27387a984708SDavid Chisnall#ifndef _LIBCPP_NO_EXCEPTIONS 27397a984708SDavid Chisnall } 27407a984708SDavid Chisnall catch (...) 27417a984708SDavid Chisnall { 27424bab9fd9SDavid Chisnall if (__begin_ != nullptr) 27437a984708SDavid Chisnall __storage_traits::deallocate(__alloc(), __begin_, __cap()); 27447a984708SDavid Chisnall __invalidate_all_iterators(); 27457a984708SDavid Chisnall throw; 27467a984708SDavid Chisnall } 27477a984708SDavid Chisnall#endif // _LIBCPP_NO_EXCEPTIONS 27487a984708SDavid Chisnall} 27497a984708SDavid Chisnall 27507a984708SDavid Chisnalltemplate <class _Allocator> 27517a984708SDavid Chisnalltemplate <class _InputIterator> 27527a984708SDavid Chisnallvector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, 27537a984708SDavid Chisnall typename enable_if<__is_input_iterator <_InputIterator>::value && 27547a984708SDavid Chisnall !__is_forward_iterator<_InputIterator>::value>::type*) 27554bab9fd9SDavid Chisnall : __begin_(nullptr), 27567a984708SDavid Chisnall __size_(0), 27577a984708SDavid Chisnall __cap_alloc_(0, static_cast<__storage_allocator>(__a)) 27587a984708SDavid Chisnall{ 27597a984708SDavid Chisnall#ifndef _LIBCPP_NO_EXCEPTIONS 27607a984708SDavid Chisnall try 27617a984708SDavid Chisnall { 27627a984708SDavid Chisnall#endif // _LIBCPP_NO_EXCEPTIONS 27637a984708SDavid Chisnall for (; __first != __last; ++__first) 27647a984708SDavid Chisnall push_back(*__first); 27657a984708SDavid Chisnall#ifndef _LIBCPP_NO_EXCEPTIONS 27667a984708SDavid Chisnall } 27677a984708SDavid Chisnall catch (...) 27687a984708SDavid Chisnall { 27694bab9fd9SDavid Chisnall if (__begin_ != nullptr) 27707a984708SDavid Chisnall __storage_traits::deallocate(__alloc(), __begin_, __cap()); 27717a984708SDavid Chisnall __invalidate_all_iterators(); 27727a984708SDavid Chisnall throw; 27737a984708SDavid Chisnall } 27747a984708SDavid Chisnall#endif // _LIBCPP_NO_EXCEPTIONS 27757a984708SDavid Chisnall} 27767a984708SDavid Chisnall 27777a984708SDavid Chisnalltemplate <class _Allocator> 27787a984708SDavid Chisnalltemplate <class _ForwardIterator> 27797a984708SDavid Chisnallvector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, 27807a984708SDavid Chisnall typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*) 27814bab9fd9SDavid Chisnall : __begin_(nullptr), 27827a984708SDavid Chisnall __size_(0), 27837a984708SDavid Chisnall __cap_alloc_(0) 27847a984708SDavid Chisnall{ 27857a984708SDavid Chisnall size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); 27867a984708SDavid Chisnall if (__n > 0) 27877a984708SDavid Chisnall { 27884ba319b5SDimitry Andric __vallocate(__n); 27897a984708SDavid Chisnall __construct_at_end(__first, __last); 27907a984708SDavid Chisnall } 27917a984708SDavid Chisnall} 27927a984708SDavid Chisnall 27937a984708SDavid Chisnalltemplate <class _Allocator> 27947a984708SDavid Chisnalltemplate <class _ForwardIterator> 27957a984708SDavid Chisnallvector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, 27967a984708SDavid Chisnall typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*) 27974bab9fd9SDavid Chisnall : __begin_(nullptr), 27987a984708SDavid Chisnall __size_(0), 27997a984708SDavid Chisnall __cap_alloc_(0, static_cast<__storage_allocator>(__a)) 28007a984708SDavid Chisnall{ 28017a984708SDavid Chisnall size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); 28027a984708SDavid Chisnall if (__n > 0) 28037a984708SDavid Chisnall { 28044ba319b5SDimitry Andric __vallocate(__n); 28057a984708SDavid Chisnall __construct_at_end(__first, __last); 28067a984708SDavid Chisnall } 28077a984708SDavid Chisnall} 28087a984708SDavid Chisnall 2809540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG 28107a984708SDavid Chisnall 28117a984708SDavid Chisnalltemplate <class _Allocator> 28127a984708SDavid Chisnallvector<bool, _Allocator>::vector(initializer_list<value_type> __il) 28134bab9fd9SDavid Chisnall : __begin_(nullptr), 28147a984708SDavid Chisnall __size_(0), 28157a984708SDavid Chisnall __cap_alloc_(0) 28167a984708SDavid Chisnall{ 28177a984708SDavid Chisnall size_type __n = static_cast<size_type>(__il.size()); 28187a984708SDavid Chisnall if (__n > 0) 28197a984708SDavid Chisnall { 28204ba319b5SDimitry Andric __vallocate(__n); 28217a984708SDavid Chisnall __construct_at_end(__il.begin(), __il.end()); 28227a984708SDavid Chisnall } 28237a984708SDavid Chisnall} 28247a984708SDavid Chisnall 28257a984708SDavid Chisnalltemplate <class _Allocator> 28267a984708SDavid Chisnallvector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a) 28274bab9fd9SDavid Chisnall : __begin_(nullptr), 28287a984708SDavid Chisnall __size_(0), 28297a984708SDavid Chisnall __cap_alloc_(0, static_cast<__storage_allocator>(__a)) 28307a984708SDavid Chisnall{ 28317a984708SDavid Chisnall size_type __n = static_cast<size_type>(__il.size()); 28327a984708SDavid Chisnall if (__n > 0) 28337a984708SDavid Chisnall { 28344ba319b5SDimitry Andric __vallocate(__n); 28357a984708SDavid Chisnall __construct_at_end(__il.begin(), __il.end()); 28367a984708SDavid Chisnall } 28377a984708SDavid Chisnall} 28387a984708SDavid Chisnall 2839540d2a8bSDimitry Andric#endif // _LIBCPP_CXX03_LANG 28407a984708SDavid Chisnall 28417a984708SDavid Chisnalltemplate <class _Allocator> 28427a984708SDavid Chisnallvector<bool, _Allocator>::~vector() 28437a984708SDavid Chisnall{ 28444bab9fd9SDavid Chisnall if (__begin_ != nullptr) 28457a984708SDavid Chisnall __storage_traits::deallocate(__alloc(), __begin_, __cap()); 28467a984708SDavid Chisnall __invalidate_all_iterators(); 28477a984708SDavid Chisnall} 28487a984708SDavid Chisnall 28497a984708SDavid Chisnalltemplate <class _Allocator> 28507a984708SDavid Chisnallvector<bool, _Allocator>::vector(const vector& __v) 28514bab9fd9SDavid Chisnall : __begin_(nullptr), 28527a984708SDavid Chisnall __size_(0), 28537a984708SDavid Chisnall __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc())) 28547a984708SDavid Chisnall{ 28557a984708SDavid Chisnall if (__v.size() > 0) 28567a984708SDavid Chisnall { 28574ba319b5SDimitry Andric __vallocate(__v.size()); 28587a984708SDavid Chisnall __construct_at_end(__v.begin(), __v.end()); 28597a984708SDavid Chisnall } 28607a984708SDavid Chisnall} 28617a984708SDavid Chisnall 28627a984708SDavid Chisnalltemplate <class _Allocator> 28637a984708SDavid Chisnallvector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a) 28644bab9fd9SDavid Chisnall : __begin_(nullptr), 28657a984708SDavid Chisnall __size_(0), 28667a984708SDavid Chisnall __cap_alloc_(0, __a) 28677a984708SDavid Chisnall{ 28687a984708SDavid Chisnall if (__v.size() > 0) 28697a984708SDavid Chisnall { 28704ba319b5SDimitry Andric __vallocate(__v.size()); 28717a984708SDavid Chisnall __construct_at_end(__v.begin(), __v.end()); 28727a984708SDavid Chisnall } 28737a984708SDavid Chisnall} 28747a984708SDavid Chisnall 28757a984708SDavid Chisnalltemplate <class _Allocator> 28767a984708SDavid Chisnallvector<bool, _Allocator>& 28777a984708SDavid Chisnallvector<bool, _Allocator>::operator=(const vector& __v) 28787a984708SDavid Chisnall{ 28797a984708SDavid Chisnall if (this != &__v) 28807a984708SDavid Chisnall { 28817a984708SDavid Chisnall __copy_assign_alloc(__v); 28827a984708SDavid Chisnall if (__v.__size_) 28837a984708SDavid Chisnall { 28847a984708SDavid Chisnall if (__v.__size_ > capacity()) 28857a984708SDavid Chisnall { 28864ba319b5SDimitry Andric __vdeallocate(); 28874ba319b5SDimitry Andric __vallocate(__v.__size_); 28887a984708SDavid Chisnall } 28897a984708SDavid Chisnall _VSTD::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_); 28907a984708SDavid Chisnall } 28917a984708SDavid Chisnall __size_ = __v.__size_; 28927a984708SDavid Chisnall } 28937a984708SDavid Chisnall return *this; 28947a984708SDavid Chisnall} 28957a984708SDavid Chisnall 2896540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG 28977a984708SDavid Chisnall 28987a984708SDavid Chisnalltemplate <class _Allocator> 28994ba319b5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY vector<bool, _Allocator>::vector(vector&& __v) 2900854fa44bSDimitry Andric#if _LIBCPP_STD_VER > 14 2901854fa44bSDimitry Andric _NOEXCEPT 2902854fa44bSDimitry Andric#else 29037a984708SDavid Chisnall _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) 2904854fa44bSDimitry Andric#endif 29057a984708SDavid Chisnall : __begin_(__v.__begin_), 29067a984708SDavid Chisnall __size_(__v.__size_), 29074ba319b5SDimitry Andric __cap_alloc_(std::move(__v.__cap_alloc_)) { 29084bab9fd9SDavid Chisnall __v.__begin_ = nullptr; 29097a984708SDavid Chisnall __v.__size_ = 0; 29107a984708SDavid Chisnall __v.__cap() = 0; 29117a984708SDavid Chisnall} 29127a984708SDavid Chisnall 29137a984708SDavid Chisnalltemplate <class _Allocator> 29147a984708SDavid Chisnallvector<bool, _Allocator>::vector(vector&& __v, const allocator_type& __a) 29154bab9fd9SDavid Chisnall : __begin_(nullptr), 29167a984708SDavid Chisnall __size_(0), 29177a984708SDavid Chisnall __cap_alloc_(0, __a) 29187a984708SDavid Chisnall{ 29197a984708SDavid Chisnall if (__a == allocator_type(__v.__alloc())) 29207a984708SDavid Chisnall { 29217a984708SDavid Chisnall this->__begin_ = __v.__begin_; 29227a984708SDavid Chisnall this->__size_ = __v.__size_; 29237a984708SDavid Chisnall this->__cap() = __v.__cap(); 29247a984708SDavid Chisnall __v.__begin_ = nullptr; 29257a984708SDavid Chisnall __v.__cap() = __v.__size_ = 0; 29267a984708SDavid Chisnall } 29277a984708SDavid Chisnall else if (__v.size() > 0) 29287a984708SDavid Chisnall { 29294ba319b5SDimitry Andric __vallocate(__v.size()); 29307a984708SDavid Chisnall __construct_at_end(__v.begin(), __v.end()); 29317a984708SDavid Chisnall } 29327a984708SDavid Chisnall} 29337a984708SDavid Chisnall 29347a984708SDavid Chisnalltemplate <class _Allocator> 29354f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 29367a984708SDavid Chisnallvector<bool, _Allocator>& 29377a984708SDavid Chisnallvector<bool, _Allocator>::operator=(vector&& __v) 29389729cf09SDimitry Andric _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) 29397a984708SDavid Chisnall{ 29407a984708SDavid Chisnall __move_assign(__v, integral_constant<bool, 29417a984708SDavid Chisnall __storage_traits::propagate_on_container_move_assignment::value>()); 2942936e9439SDimitry Andric return *this; 29437a984708SDavid Chisnall} 29447a984708SDavid Chisnall 29457a984708SDavid Chisnalltemplate <class _Allocator> 29467a984708SDavid Chisnallvoid 29477a984708SDavid Chisnallvector<bool, _Allocator>::__move_assign(vector& __c, false_type) 29487a984708SDavid Chisnall{ 29497a984708SDavid Chisnall if (__alloc() != __c.__alloc()) 29507a984708SDavid Chisnall assign(__c.begin(), __c.end()); 29517a984708SDavid Chisnall else 29527a984708SDavid Chisnall __move_assign(__c, true_type()); 29537a984708SDavid Chisnall} 29547a984708SDavid Chisnall 29557a984708SDavid Chisnalltemplate <class _Allocator> 29567a984708SDavid Chisnallvoid 29577a984708SDavid Chisnallvector<bool, _Allocator>::__move_assign(vector& __c, true_type) 29587a984708SDavid Chisnall _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) 29597a984708SDavid Chisnall{ 29604ba319b5SDimitry Andric __vdeallocate(); 2961d72607e9SDimitry Andric __move_assign_alloc(__c); 29627a984708SDavid Chisnall this->__begin_ = __c.__begin_; 29637a984708SDavid Chisnall this->__size_ = __c.__size_; 29647a984708SDavid Chisnall this->__cap() = __c.__cap(); 29657a984708SDavid Chisnall __c.__begin_ = nullptr; 29667a984708SDavid Chisnall __c.__cap() = __c.__size_ = 0; 29677a984708SDavid Chisnall} 29687a984708SDavid Chisnall 2969540d2a8bSDimitry Andric#endif // !_LIBCPP_CXX03_LANG 29707a984708SDavid Chisnall 29717a984708SDavid Chisnalltemplate <class _Allocator> 29727a984708SDavid Chisnallvoid 29737a984708SDavid Chisnallvector<bool, _Allocator>::assign(size_type __n, const value_type& __x) 29747a984708SDavid Chisnall{ 29757a984708SDavid Chisnall __size_ = 0; 29767a984708SDavid Chisnall if (__n > 0) 29777a984708SDavid Chisnall { 29787a984708SDavid Chisnall size_type __c = capacity(); 29797a984708SDavid Chisnall if (__n <= __c) 29807a984708SDavid Chisnall __size_ = __n; 29817a984708SDavid Chisnall else 29827a984708SDavid Chisnall { 29837a984708SDavid Chisnall vector __v(__alloc()); 29847a984708SDavid Chisnall __v.reserve(__recommend(__n)); 29857a984708SDavid Chisnall __v.__size_ = __n; 29867a984708SDavid Chisnall swap(__v); 29877a984708SDavid Chisnall } 29887a984708SDavid Chisnall _VSTD::fill_n(begin(), __n, __x); 29897a984708SDavid Chisnall } 2990aed8d94eSDimitry Andric __invalidate_all_iterators(); 29917a984708SDavid Chisnall} 29927a984708SDavid Chisnall 29937a984708SDavid Chisnalltemplate <class _Allocator> 29947a984708SDavid Chisnalltemplate <class _InputIterator> 29957a984708SDavid Chisnalltypename enable_if 29967a984708SDavid Chisnall< 29977a984708SDavid Chisnall __is_input_iterator<_InputIterator>::value && 29987a984708SDavid Chisnall !__is_forward_iterator<_InputIterator>::value, 29997a984708SDavid Chisnall void 30007a984708SDavid Chisnall>::type 30017a984708SDavid Chisnallvector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last) 30027a984708SDavid Chisnall{ 30037a984708SDavid Chisnall clear(); 30047a984708SDavid Chisnall for (; __first != __last; ++__first) 30057a984708SDavid Chisnall push_back(*__first); 30067a984708SDavid Chisnall} 30077a984708SDavid Chisnall 30087a984708SDavid Chisnalltemplate <class _Allocator> 30097a984708SDavid Chisnalltemplate <class _ForwardIterator> 30107a984708SDavid Chisnalltypename enable_if 30117a984708SDavid Chisnall< 30127a984708SDavid Chisnall __is_forward_iterator<_ForwardIterator>::value, 30137a984708SDavid Chisnall void 30147a984708SDavid Chisnall>::type 30157a984708SDavid Chisnallvector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) 30167a984708SDavid Chisnall{ 30177a984708SDavid Chisnall clear(); 3018aed8d94eSDimitry Andric difference_type __ns = _VSTD::distance(__first, __last); 3019aed8d94eSDimitry Andric _LIBCPP_ASSERT(__ns >= 0, "invalid range specified"); 3020aed8d94eSDimitry Andric const size_t __n = static_cast<size_type>(__ns); 30217a984708SDavid Chisnall if (__n) 30227a984708SDavid Chisnall { 30237a984708SDavid Chisnall if (__n > capacity()) 30247a984708SDavid Chisnall { 30254ba319b5SDimitry Andric __vdeallocate(); 30264ba319b5SDimitry Andric __vallocate(__n); 30277a984708SDavid Chisnall } 30287a984708SDavid Chisnall __construct_at_end(__first, __last); 30297a984708SDavid Chisnall } 30307a984708SDavid Chisnall} 30317a984708SDavid Chisnall 30327a984708SDavid Chisnalltemplate <class _Allocator> 30337a984708SDavid Chisnallvoid 30347a984708SDavid Chisnallvector<bool, _Allocator>::reserve(size_type __n) 30357a984708SDavid Chisnall{ 30367a984708SDavid Chisnall if (__n > capacity()) 30377a984708SDavid Chisnall { 30387a984708SDavid Chisnall vector __v(this->__alloc()); 30394ba319b5SDimitry Andric __v.__vallocate(__n); 30407a984708SDavid Chisnall __v.__construct_at_end(this->begin(), this->end()); 30417a984708SDavid Chisnall swap(__v); 30427a984708SDavid Chisnall __invalidate_all_iterators(); 30437a984708SDavid Chisnall } 30447a984708SDavid Chisnall} 30457a984708SDavid Chisnall 30467a984708SDavid Chisnalltemplate <class _Allocator> 30477a984708SDavid Chisnallvoid 30487a984708SDavid Chisnallvector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT 30497a984708SDavid Chisnall{ 30507a984708SDavid Chisnall if (__external_cap_to_internal(size()) > __cap()) 30517a984708SDavid Chisnall { 30527a984708SDavid Chisnall#ifndef _LIBCPP_NO_EXCEPTIONS 30537a984708SDavid Chisnall try 30547a984708SDavid Chisnall { 30557a984708SDavid Chisnall#endif // _LIBCPP_NO_EXCEPTIONS 30567a984708SDavid Chisnall vector(*this, allocator_type(__alloc())).swap(*this); 30577a984708SDavid Chisnall#ifndef _LIBCPP_NO_EXCEPTIONS 30587a984708SDavid Chisnall } 30597a984708SDavid Chisnall catch (...) 30607a984708SDavid Chisnall { 30617a984708SDavid Chisnall } 30627a984708SDavid Chisnall#endif // _LIBCPP_NO_EXCEPTIONS 30637a984708SDavid Chisnall } 30647a984708SDavid Chisnall} 30657a984708SDavid Chisnall 30667a984708SDavid Chisnalltemplate <class _Allocator> 30677a984708SDavid Chisnalltypename vector<bool, _Allocator>::reference 30687a984708SDavid Chisnallvector<bool, _Allocator>::at(size_type __n) 30697a984708SDavid Chisnall{ 30707a984708SDavid Chisnall if (__n >= size()) 30717a984708SDavid Chisnall this->__throw_out_of_range(); 30727a984708SDavid Chisnall return (*this)[__n]; 30737a984708SDavid Chisnall} 30747a984708SDavid Chisnall 30757a984708SDavid Chisnalltemplate <class _Allocator> 30767a984708SDavid Chisnalltypename vector<bool, _Allocator>::const_reference 30777a984708SDavid Chisnallvector<bool, _Allocator>::at(size_type __n) const 30787a984708SDavid Chisnall{ 30797a984708SDavid Chisnall if (__n >= size()) 30807a984708SDavid Chisnall this->__throw_out_of_range(); 30817a984708SDavid Chisnall return (*this)[__n]; 30827a984708SDavid Chisnall} 30837a984708SDavid Chisnall 30847a984708SDavid Chisnalltemplate <class _Allocator> 30857a984708SDavid Chisnallvoid 30867a984708SDavid Chisnallvector<bool, _Allocator>::push_back(const value_type& __x) 30877a984708SDavid Chisnall{ 30887a984708SDavid Chisnall if (this->__size_ == this->capacity()) 30897a984708SDavid Chisnall reserve(__recommend(this->__size_ + 1)); 30907a984708SDavid Chisnall ++this->__size_; 30917a984708SDavid Chisnall back() = __x; 30927a984708SDavid Chisnall} 30937a984708SDavid Chisnall 30947a984708SDavid Chisnalltemplate <class _Allocator> 30957a984708SDavid Chisnalltypename vector<bool, _Allocator>::iterator 30967a984708SDavid Chisnallvector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x) 30977a984708SDavid Chisnall{ 30987a984708SDavid Chisnall iterator __r; 30997a984708SDavid Chisnall if (size() < capacity()) 31007a984708SDavid Chisnall { 31017a984708SDavid Chisnall const_iterator __old_end = end(); 31027a984708SDavid Chisnall ++__size_; 31037a984708SDavid Chisnall _VSTD::copy_backward(__position, __old_end, end()); 31047a984708SDavid Chisnall __r = __const_iterator_cast(__position); 31057a984708SDavid Chisnall } 31067a984708SDavid Chisnall else 31077a984708SDavid Chisnall { 31087a984708SDavid Chisnall vector __v(__alloc()); 31097a984708SDavid Chisnall __v.reserve(__recommend(__size_ + 1)); 31107a984708SDavid Chisnall __v.__size_ = __size_ + 1; 31117a984708SDavid Chisnall __r = _VSTD::copy(cbegin(), __position, __v.begin()); 31127a984708SDavid Chisnall _VSTD::copy_backward(__position, cend(), __v.end()); 31137a984708SDavid Chisnall swap(__v); 31147a984708SDavid Chisnall } 31157a984708SDavid Chisnall *__r = __x; 31167a984708SDavid Chisnall return __r; 31177a984708SDavid Chisnall} 31187a984708SDavid Chisnall 31197a984708SDavid Chisnalltemplate <class _Allocator> 31207a984708SDavid Chisnalltypename vector<bool, _Allocator>::iterator 31217a984708SDavid Chisnallvector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x) 31227a984708SDavid Chisnall{ 31237a984708SDavid Chisnall iterator __r; 31247a984708SDavid Chisnall size_type __c = capacity(); 31257a984708SDavid Chisnall if (__n <= __c && size() <= __c - __n) 31267a984708SDavid Chisnall { 31277a984708SDavid Chisnall const_iterator __old_end = end(); 31287a984708SDavid Chisnall __size_ += __n; 31297a984708SDavid Chisnall _VSTD::copy_backward(__position, __old_end, end()); 31307a984708SDavid Chisnall __r = __const_iterator_cast(__position); 31317a984708SDavid Chisnall } 31327a984708SDavid Chisnall else 31337a984708SDavid Chisnall { 31347a984708SDavid Chisnall vector __v(__alloc()); 31357a984708SDavid Chisnall __v.reserve(__recommend(__size_ + __n)); 31367a984708SDavid Chisnall __v.__size_ = __size_ + __n; 31377a984708SDavid Chisnall __r = _VSTD::copy(cbegin(), __position, __v.begin()); 31387a984708SDavid Chisnall _VSTD::copy_backward(__position, cend(), __v.end()); 31397a984708SDavid Chisnall swap(__v); 31407a984708SDavid Chisnall } 31417a984708SDavid Chisnall _VSTD::fill_n(__r, __n, __x); 31427a984708SDavid Chisnall return __r; 31437a984708SDavid Chisnall} 31447a984708SDavid Chisnall 31457a984708SDavid Chisnalltemplate <class _Allocator> 31467a984708SDavid Chisnalltemplate <class _InputIterator> 31477a984708SDavid Chisnalltypename enable_if 31487a984708SDavid Chisnall< 31497a984708SDavid Chisnall __is_input_iterator <_InputIterator>::value && 31507a984708SDavid Chisnall !__is_forward_iterator<_InputIterator>::value, 31517a984708SDavid Chisnall typename vector<bool, _Allocator>::iterator 31527a984708SDavid Chisnall>::type 31537a984708SDavid Chisnallvector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last) 31547a984708SDavid Chisnall{ 31557a984708SDavid Chisnall difference_type __off = __position - begin(); 31567a984708SDavid Chisnall iterator __p = __const_iterator_cast(__position); 31577a984708SDavid Chisnall iterator __old_end = end(); 31587a984708SDavid Chisnall for (; size() != capacity() && __first != __last; ++__first) 31597a984708SDavid Chisnall { 31607a984708SDavid Chisnall ++this->__size_; 31617a984708SDavid Chisnall back() = *__first; 31627a984708SDavid Chisnall } 31637a984708SDavid Chisnall vector __v(__alloc()); 31647a984708SDavid Chisnall if (__first != __last) 31657a984708SDavid Chisnall { 31667a984708SDavid Chisnall#ifndef _LIBCPP_NO_EXCEPTIONS 31677a984708SDavid Chisnall try 31687a984708SDavid Chisnall { 31697a984708SDavid Chisnall#endif // _LIBCPP_NO_EXCEPTIONS 31707a984708SDavid Chisnall __v.assign(__first, __last); 31717a984708SDavid Chisnall difference_type __old_size = static_cast<difference_type>(__old_end - begin()); 31727a984708SDavid Chisnall difference_type __old_p = __p - begin(); 31737a984708SDavid Chisnall reserve(__recommend(size() + __v.size())); 31747a984708SDavid Chisnall __p = begin() + __old_p; 31757a984708SDavid Chisnall __old_end = begin() + __old_size; 31767a984708SDavid Chisnall#ifndef _LIBCPP_NO_EXCEPTIONS 31777a984708SDavid Chisnall } 31787a984708SDavid Chisnall catch (...) 31797a984708SDavid Chisnall { 31807a984708SDavid Chisnall erase(__old_end, end()); 31817a984708SDavid Chisnall throw; 31827a984708SDavid Chisnall } 31837a984708SDavid Chisnall#endif // _LIBCPP_NO_EXCEPTIONS 31847a984708SDavid Chisnall } 31857a984708SDavid Chisnall __p = _VSTD::rotate(__p, __old_end, end()); 31867a984708SDavid Chisnall insert(__p, __v.begin(), __v.end()); 31877a984708SDavid Chisnall return begin() + __off; 31887a984708SDavid Chisnall} 31897a984708SDavid Chisnall 31907a984708SDavid Chisnalltemplate <class _Allocator> 31917a984708SDavid Chisnalltemplate <class _ForwardIterator> 31927a984708SDavid Chisnalltypename enable_if 31937a984708SDavid Chisnall< 31947a984708SDavid Chisnall __is_forward_iterator<_ForwardIterator>::value, 31957a984708SDavid Chisnall typename vector<bool, _Allocator>::iterator 31967a984708SDavid Chisnall>::type 31977a984708SDavid Chisnallvector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last) 31987a984708SDavid Chisnall{ 3199aed8d94eSDimitry Andric const difference_type __n_signed = _VSTD::distance(__first, __last); 3200aed8d94eSDimitry Andric _LIBCPP_ASSERT(__n_signed >= 0, "invalid range specified"); 3201aed8d94eSDimitry Andric const size_type __n = static_cast<size_type>(__n_signed); 32027a984708SDavid Chisnall iterator __r; 32037a984708SDavid Chisnall size_type __c = capacity(); 32047a984708SDavid Chisnall if (__n <= __c && size() <= __c - __n) 32057a984708SDavid Chisnall { 32067a984708SDavid Chisnall const_iterator __old_end = end(); 32077a984708SDavid Chisnall __size_ += __n; 32087a984708SDavid Chisnall _VSTD::copy_backward(__position, __old_end, end()); 32097a984708SDavid Chisnall __r = __const_iterator_cast(__position); 32107a984708SDavid Chisnall } 32117a984708SDavid Chisnall else 32127a984708SDavid Chisnall { 32137a984708SDavid Chisnall vector __v(__alloc()); 32147a984708SDavid Chisnall __v.reserve(__recommend(__size_ + __n)); 32157a984708SDavid Chisnall __v.__size_ = __size_ + __n; 32167a984708SDavid Chisnall __r = _VSTD::copy(cbegin(), __position, __v.begin()); 32177a984708SDavid Chisnall _VSTD::copy_backward(__position, cend(), __v.end()); 32187a984708SDavid Chisnall swap(__v); 32197a984708SDavid Chisnall } 32207a984708SDavid Chisnall _VSTD::copy(__first, __last, __r); 32217a984708SDavid Chisnall return __r; 32227a984708SDavid Chisnall} 32237a984708SDavid Chisnall 32247a984708SDavid Chisnalltemplate <class _Allocator> 32254f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 32267a984708SDavid Chisnalltypename vector<bool, _Allocator>::iterator 32277a984708SDavid Chisnallvector<bool, _Allocator>::erase(const_iterator __position) 32287a984708SDavid Chisnall{ 32297a984708SDavid Chisnall iterator __r = __const_iterator_cast(__position); 32307a984708SDavid Chisnall _VSTD::copy(__position + 1, this->cend(), __r); 32317a984708SDavid Chisnall --__size_; 32327a984708SDavid Chisnall return __r; 32337a984708SDavid Chisnall} 32347a984708SDavid Chisnall 32357a984708SDavid Chisnalltemplate <class _Allocator> 32367a984708SDavid Chisnalltypename vector<bool, _Allocator>::iterator 32377a984708SDavid Chisnallvector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last) 32387a984708SDavid Chisnall{ 32397a984708SDavid Chisnall iterator __r = __const_iterator_cast(__first); 32407a984708SDavid Chisnall difference_type __d = __last - __first; 32417a984708SDavid Chisnall _VSTD::copy(__last, this->cend(), __r); 32427a984708SDavid Chisnall __size_ -= __d; 32437a984708SDavid Chisnall return __r; 32447a984708SDavid Chisnall} 32457a984708SDavid Chisnall 32467a984708SDavid Chisnalltemplate <class _Allocator> 32477a984708SDavid Chisnallvoid 32487a984708SDavid Chisnallvector<bool, _Allocator>::swap(vector& __x) 3249854fa44bSDimitry Andric#if _LIBCPP_STD_VER >= 14 3250854fa44bSDimitry Andric _NOEXCEPT 3251854fa44bSDimitry Andric#else 32527a984708SDavid Chisnall _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || 32537a984708SDavid Chisnall __is_nothrow_swappable<allocator_type>::value) 3254854fa44bSDimitry Andric#endif 32557a984708SDavid Chisnall{ 32567a984708SDavid Chisnall _VSTD::swap(this->__begin_, __x.__begin_); 32577a984708SDavid Chisnall _VSTD::swap(this->__size_, __x.__size_); 32587a984708SDavid Chisnall _VSTD::swap(this->__cap(), __x.__cap()); 3259854fa44bSDimitry Andric __swap_allocator(this->__alloc(), __x.__alloc(), 3260854fa44bSDimitry Andric integral_constant<bool, __alloc_traits::propagate_on_container_swap::value>()); 32617a984708SDavid Chisnall} 32627a984708SDavid Chisnall 32637a984708SDavid Chisnalltemplate <class _Allocator> 32647a984708SDavid Chisnallvoid 32657a984708SDavid Chisnallvector<bool, _Allocator>::resize(size_type __sz, value_type __x) 32667a984708SDavid Chisnall{ 32677a984708SDavid Chisnall size_type __cs = size(); 32687a984708SDavid Chisnall if (__cs < __sz) 32697a984708SDavid Chisnall { 32707a984708SDavid Chisnall iterator __r; 32717a984708SDavid Chisnall size_type __c = capacity(); 32727a984708SDavid Chisnall size_type __n = __sz - __cs; 32737a984708SDavid Chisnall if (__n <= __c && __cs <= __c - __n) 32747a984708SDavid Chisnall { 32757a984708SDavid Chisnall __r = end(); 32767a984708SDavid Chisnall __size_ += __n; 32777a984708SDavid Chisnall } 32787a984708SDavid Chisnall else 32797a984708SDavid Chisnall { 32807a984708SDavid Chisnall vector __v(__alloc()); 32817a984708SDavid Chisnall __v.reserve(__recommend(__size_ + __n)); 32827a984708SDavid Chisnall __v.__size_ = __size_ + __n; 32837a984708SDavid Chisnall __r = _VSTD::copy(cbegin(), cend(), __v.begin()); 32847a984708SDavid Chisnall swap(__v); 32857a984708SDavid Chisnall } 32867a984708SDavid Chisnall _VSTD::fill_n(__r, __n, __x); 32877a984708SDavid Chisnall } 32887a984708SDavid Chisnall else 32897a984708SDavid Chisnall __size_ = __sz; 32907a984708SDavid Chisnall} 32917a984708SDavid Chisnall 32927a984708SDavid Chisnalltemplate <class _Allocator> 32937a984708SDavid Chisnallvoid 32947a984708SDavid Chisnallvector<bool, _Allocator>::flip() _NOEXCEPT 32957a984708SDavid Chisnall{ 32967a984708SDavid Chisnall // do middle whole words 32977a984708SDavid Chisnall size_type __n = __size_; 32987a984708SDavid Chisnall __storage_pointer __p = __begin_; 32997a984708SDavid Chisnall for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) 33007a984708SDavid Chisnall *__p = ~*__p; 33017a984708SDavid Chisnall // do last partial word 33027a984708SDavid Chisnall if (__n > 0) 33037a984708SDavid Chisnall { 33047a984708SDavid Chisnall __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); 33057a984708SDavid Chisnall __storage_type __b = *__p & __m; 33067a984708SDavid Chisnall *__p &= ~__m; 33077a984708SDavid Chisnall *__p |= ~__b & __m; 33087a984708SDavid Chisnall } 33097a984708SDavid Chisnall} 33107a984708SDavid Chisnall 33117a984708SDavid Chisnalltemplate <class _Allocator> 33127a984708SDavid Chisnallbool 33137a984708SDavid Chisnallvector<bool, _Allocator>::__invariants() const 33147a984708SDavid Chisnall{ 33154bab9fd9SDavid Chisnall if (this->__begin_ == nullptr) 33167a984708SDavid Chisnall { 33177a984708SDavid Chisnall if (this->__size_ != 0 || this->__cap() != 0) 33187a984708SDavid Chisnall return false; 33197a984708SDavid Chisnall } 33207a984708SDavid Chisnall else 33217a984708SDavid Chisnall { 33227a984708SDavid Chisnall if (this->__cap() == 0) 33237a984708SDavid Chisnall return false; 33247a984708SDavid Chisnall if (this->__size_ > this->capacity()) 33257a984708SDavid Chisnall return false; 33267a984708SDavid Chisnall } 33277a984708SDavid Chisnall return true; 33287a984708SDavid Chisnall} 33297a984708SDavid Chisnall 33307a984708SDavid Chisnalltemplate <class _Allocator> 33317a984708SDavid Chisnallsize_t 33327a984708SDavid Chisnallvector<bool, _Allocator>::__hash_code() const _NOEXCEPT 33337a984708SDavid Chisnall{ 33347a984708SDavid Chisnall size_t __h = 0; 33357a984708SDavid Chisnall // do middle whole words 33367a984708SDavid Chisnall size_type __n = __size_; 33377a984708SDavid Chisnall __storage_pointer __p = __begin_; 33387a984708SDavid Chisnall for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) 33397a984708SDavid Chisnall __h ^= *__p; 33407a984708SDavid Chisnall // do last partial word 33417a984708SDavid Chisnall if (__n > 0) 33427a984708SDavid Chisnall { 33437a984708SDavid Chisnall const __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); 33447a984708SDavid Chisnall __h ^= *__p & __m; 33457a984708SDavid Chisnall } 33467a984708SDavid Chisnall return __h; 33477a984708SDavid Chisnall} 33487a984708SDavid Chisnall 33497a984708SDavid Chisnalltemplate <class _Allocator> 3350aed8d94eSDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<vector<bool, _Allocator> > 33517a984708SDavid Chisnall : public unary_function<vector<bool, _Allocator>, size_t> 33527a984708SDavid Chisnall{ 33537a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY 33547a984708SDavid Chisnall size_t operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT 33557a984708SDavid Chisnall {return __vec.__hash_code();} 33567a984708SDavid Chisnall}; 33577a984708SDavid Chisnall 33587a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 33594f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 33607a984708SDavid Chisnallbool 33617a984708SDavid Chisnalloperator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) 33627a984708SDavid Chisnall{ 33637a984708SDavid Chisnall const typename vector<_Tp, _Allocator>::size_type __sz = __x.size(); 33647a984708SDavid Chisnall return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin()); 33657a984708SDavid Chisnall} 33667a984708SDavid Chisnall 33677a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 33684f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 33697a984708SDavid Chisnallbool 33707a984708SDavid Chisnalloperator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) 33717a984708SDavid Chisnall{ 33727a984708SDavid Chisnall return !(__x == __y); 33737a984708SDavid Chisnall} 33747a984708SDavid Chisnall 33757a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 33764f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 33777a984708SDavid Chisnallbool 33787a984708SDavid Chisnalloperator< (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) 33797a984708SDavid Chisnall{ 33807a984708SDavid Chisnall return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); 33817a984708SDavid Chisnall} 33827a984708SDavid Chisnall 33837a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 33844f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 33857a984708SDavid Chisnallbool 33867a984708SDavid Chisnalloperator> (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) 33877a984708SDavid Chisnall{ 33887a984708SDavid Chisnall return __y < __x; 33897a984708SDavid Chisnall} 33907a984708SDavid Chisnall 33917a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 33924f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 33937a984708SDavid Chisnallbool 33947a984708SDavid Chisnalloperator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) 33957a984708SDavid Chisnall{ 33967a984708SDavid Chisnall return !(__x < __y); 33977a984708SDavid Chisnall} 33987a984708SDavid Chisnall 33997a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 34004f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 34017a984708SDavid Chisnallbool 34027a984708SDavid Chisnalloperator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) 34037a984708SDavid Chisnall{ 34047a984708SDavid Chisnall return !(__y < __x); 34057a984708SDavid Chisnall} 34067a984708SDavid Chisnall 34077a984708SDavid Chisnalltemplate <class _Tp, class _Allocator> 34084f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 34097a984708SDavid Chisnallvoid 34107a984708SDavid Chisnallswap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y) 34117a984708SDavid Chisnall _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) 34127a984708SDavid Chisnall{ 34137a984708SDavid Chisnall __x.swap(__y); 34147a984708SDavid Chisnall} 34157a984708SDavid Chisnall 3416*b5893f02SDimitry Andric#if _LIBCPP_STD_VER > 17 3417*b5893f02SDimitry Andrictemplate <class _Tp, class _Allocator, class _Up> 3418*b5893f02SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 3419*b5893f02SDimitry Andricvoid erase(vector<_Tp, _Allocator>& __c, const _Up& __v) 3420*b5893f02SDimitry Andric{ __c.erase(_VSTD::remove(__c.begin(), __c.end(), __v), __c.end()); } 3421*b5893f02SDimitry Andric 3422*b5893f02SDimitry Andrictemplate <class _Tp, class _Allocator, class _Predicate> 3423*b5893f02SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 3424*b5893f02SDimitry Andricvoid erase_if(vector<_Tp, _Allocator>& __c, _Predicate __pred) 3425*b5893f02SDimitry Andric{ __c.erase(_VSTD::remove_if(__c.begin(), __c.end(), __pred), __c.end()); } 3426*b5893f02SDimitry Andric#endif 3427*b5893f02SDimitry Andric 34287a984708SDavid Chisnall_LIBCPP_END_NAMESPACE_STD 34297a984708SDavid Chisnall 3430f9448bf3SDimitry Andric_LIBCPP_POP_MACROS 3431f9448bf3SDimitry Andric 34327a984708SDavid Chisnall#endif // _LIBCPP_VECTOR 3433