This header is part of thecontainers library.
Includes | ||
(C++20) | Three-way comparison operator support[edit] | |
(C++11) | std::initializer_list class template[edit] | |
Classes | ||
resizable contiguous array (class template)[edit] | ||
space-efficient dynamic bitset (class template specialization)[edit] | ||
(C++11) | hash support forstd::vector<bool> (class template specialization) | |
Forward declarations | ||
Defined in header <functional> | ||
(C++11) | hash function object (class template)[edit] | |
Functions | ||
(removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(C++20) | lexicographically compares the values of twovector s(function template)[edit] | |
specializes thestd::swap algorithm (function template)[edit] | ||
erases all elements satisfying specific criteria (function template)[edit] | ||
Range access | ||
(C++11)(C++14) | returns an iterator to the beginning of a container or array (function template)[edit] | |
(C++11)(C++14) | returns an iterator to the end of a container or array (function template)[edit] | |
(C++14) | returns a reverse iterator to the beginning of a container or array (function template)[edit] | |
(C++14) | returns a reverse end iterator for a container or array (function template)[edit] | |
(C++17)(C++20) | returns the size of a container or array (function template)[edit] | |
(C++17) | checks whether the container is empty (function template)[edit] | |
(C++17) | obtains the pointer to the underlying array (function template)[edit] |
#include <compare>#include <initializer_list> namespace std{// class template vectortemplate<class T,class Allocator= allocator<T>>class vector; template<class T,class Allocator>constexprbool operator==(const vector<T, Allocator>& x,const vector<T, Allocator>& y);template<class T,class Allocator>constexpr/*synth-three-way-result*/<T> operator<=>(const vector<T, Allocator>& x,const vector<T, Allocator>& y); template<class T,class Allocator>constexprvoid swap(vector<T, Allocator>& x, vector<T, Allocator>& y)noexcept(noexcept(x.swap(y))); // erasuretemplate<class T,class Allocator,class U= T>constexprtypename vector<T, Allocator>::size_type erase(vector<T, Allocator>& c,const U& value);template<class T,class Allocator,class Predicate>constexprtypename vector<T, Allocator>::size_type erase_if(vector<T, Allocator>& c, Predicate pred); namespace pmr{template<class T>using vector=std::vector<T, polymorphic_allocator<T>>;} // specialization of vector for bool// partial class template specialization vector<bool, Allocator>template<class Allocator>class vector<bool, Allocator>; template<class T>constexprbool/*is-vector-bool-reference*/=/* see description */;// exposition only // hash supporttemplate<class T>struct hash;template<class Allocator>struct hash<vector<bool, Allocator>>; // formatter specialization for vector<bool>template<class T,class CharT> requires/*is-vector-bool-reference*/<T>struct formatter<T, CharT>;}
namespace std{template<class T,class Allocator= allocator<T>>class vector{public:// typesusing value_type= T;using allocator_type= Allocator;using pointer=typename allocator_traits<Allocator>::pointer;using const_pointer=typename allocator_traits<Allocator>::const_pointer;using reference= value_type&;using const_reference=const value_type&;using size_type=/* implementation-defined */;using difference_type=/* implementation-defined */;using iterator=/* implementation-defined */;using const_iterator=/* implementation-defined */;using reverse_iterator=std::reverse_iterator<iterator>;using const_reverse_iterator=std::reverse_iterator<const_iterator>; // construct/copy/destroyconstexpr vector()noexcept(noexcept(Allocator())): vector(Allocator()){}constexprexplicit vector(const Allocator&)noexcept;constexprexplicit vector(size_type n,const Allocator&= Allocator());constexpr vector(size_type n,const T& value,const Allocator&= Allocator());template<class InputIter>constexpr vector(InputIter first, InputIter last,const Allocator&= Allocator());template<container-compatible-range<T> R>constexpr vector(from_range_t, R&& rg,const Allocator&= Allocator());constexpr vector(const vector& x);constexpr vector(vector&&)noexcept;constexpr vector(const vector&,const type_identity_t<Allocator>&);constexpr vector(vector&&,const type_identity_t<Allocator>&);constexpr vector(initializer_list<T>,const Allocator&= Allocator());constexpr ~vector();constexpr vector& operator=(const vector& x);constexpr vector& operator=(vector&& x)noexcept( allocator_traits<Allocator>::propagate_on_container_move_assignment::value|| allocator_traits<Allocator>::is_always_equal::value);constexpr vector& operator=(initializer_list<T>);template<class InputIter>constexprvoid assign(InputIter first, InputIter last);template<container-compatible-range<T> R>constexprvoid assign_range(R&& rg);constexprvoid assign(size_type n,const T& u);constexprvoid assign(initializer_list<T>);constexpr allocator_type get_allocator()constnoexcept; // iteratorsconstexpr iterator begin()noexcept;constexpr const_iterator begin()constnoexcept;constexpr iterator end()noexcept;constexpr const_iterator end()constnoexcept;constexpr reverse_iterator rbegin()noexcept;constexpr const_reverse_iterator rbegin()constnoexcept;constexpr reverse_iterator rend()noexcept;constexpr const_reverse_iterator rend()constnoexcept; constexpr const_iterator cbegin()constnoexcept;constexpr const_iterator cend()constnoexcept;constexpr const_reverse_iterator crbegin()constnoexcept;constexpr const_reverse_iterator crend()constnoexcept; // capacityconstexprbool empty()constnoexcept;constexpr size_type size()constnoexcept;constexpr size_type max_size()constnoexcept;constexpr size_type capacity()constnoexcept;constexprvoid resize(size_type sz);constexprvoid resize(size_type sz,const T& c);constexprvoid reserve(size_type n);constexprvoid shrink_to_fit(); // element accessconstexpr reference operator[](size_type n);constexpr const_reference operator[](size_type n)const;constexpr const_reference at(size_type n)const;constexpr reference at(size_type n);constexpr reference front();constexpr const_reference front()const;constexpr reference back();constexpr const_reference back()const; // data accessconstexpr T* data()noexcept;constexprconst T* data()constnoexcept; // modifierstemplate<class...Args>constexpr reference emplace_back(Args&&...args);constexprvoid push_back(const T& x);constexprvoid push_back(T&& x);template<container-compatible-range<T> R>constexprvoid append_range(R&& rg);constexprvoid pop_back(); template<class...Args>constexpr iterator emplace(const_iterator position, Args&&...args);constexpr iterator insert(const_iterator position,const T& x);constexpr iterator insert(const_iterator position, T&& x);constexpr iterator insert(const_iterator position, size_type n,const T& x);template<class InputIter>constexpr iterator insert(const_iterator position, InputIter first, InputIter last);template<container-compatible-range<T> R>constexpr iterator insert_range(const_iterator position, R&& rg);constexpr iterator insert(const_iterator position, initializer_list<T> il);constexpr iterator erase(const_iterator position);constexpr iterator erase(const_iterator first, const_iterator last);constexprvoid swap(vector&)noexcept( allocator_traits<Allocator>::propagate_on_container_swap::value|| allocator_traits<Allocator>::is_always_equal::value);constexprvoid clear()noexcept;}; template<class InputIter,class Allocator= allocator</*iter-value-type*/<InputIter>>> vector(InputIter, InputIter, Allocator= Allocator())-> vector</*iter-value-type*/<InputIter>, Allocator>; template<ranges::input_range R,class Allocator= allocator<ranges::range_value_t<R>>> vector(from_range_t, R&&, Allocator= Allocator())-> vector<ranges::range_value_t<R>, Allocator>;}
namespace std{template<class Allocator>class vector<bool, Allocator>{public:// typesusing value_type=bool;using allocator_type= Allocator;using pointer=/* implementation-defined */;using const_pointer=/* implementation-defined */;using const_reference=bool;using size_type=/* implementation-defined */;using difference_type=/* implementation-defined */;using iterator=/* implementation-defined */;using const_iterator=/* implementation-defined */;using reverse_iterator=std::reverse_iterator<iterator>;using const_reverse_iterator=std::reverse_iterator<const_iterator>; // bit referenceclass reference{public:constexpr reference(const reference&)=default;constexpr ~reference();constexpr operatorbool()constnoexcept;constexpr reference& operator=(bool x)noexcept;constexpr reference& operator=(const reference& x)noexcept;constexprconst reference& operator=(bool x)constnoexcept;constexprvoid flip()noexcept;// flips the bit}; // construct/copy/destroyconstexpr vector()noexcept(noexcept(Allocator())): vector(Allocator()){}constexprexplicit vector(const Allocator&)noexcept;constexprexplicit vector(size_type n,const Allocator&= Allocator());constexpr vector(size_type n,constbool& value,const Allocator&= Allocator());template<class InputIter>constexpr vector(InputIter first, InputIter last,const Allocator&= Allocator());template<container-compatible-range<bool> R>constexpr vector(from_range_t, R&& rg,const Allocator&= Allocator());constexpr vector(const vector& x);constexpr vector(vector&& x)noexcept;constexpr vector(const vector&,const type_identity_t<Allocator>&);constexpr vector(vector&&,const type_identity_t<Allocator>&);constexpr vector(initializer_list<bool>,const Allocator&= Allocator());constexpr ~vector();constexpr vector& operator=(const vector& x);constexpr vector& operator=(vector&& x)noexcept( allocator_traits<Allocator>::propagate_on_container_move_assignment::value|| allocator_traits<Allocator>::is_always_equal::value);constexpr vector& operator=(initializer_list<bool>);template<class InputIter>constexprvoid assign(InputIter first, InputIter last);template<container-compatible-range<bool> R>constexprvoid assign_range(R&& rg);constexprvoid assign(size_type n,constbool& t);constexprvoid assign(initializer_list<bool>);constexpr allocator_type get_allocator()constnoexcept; // iteratorsconstexpr iterator begin()noexcept;constexpr const_iterator begin()constnoexcept;constexpr iterator end()noexcept;constexpr const_iterator end()constnoexcept;constexpr reverse_iterator rbegin()noexcept;constexpr const_reverse_iterator rbegin()constnoexcept;constexpr reverse_iterator rend()noexcept;constexpr const_reverse_iterator rend()constnoexcept; constexpr const_iterator cbegin()constnoexcept;constexpr const_iterator cend()constnoexcept;constexpr const_reverse_iterator crbegin()constnoexcept;constexpr const_reverse_iterator crend()constnoexcept; // capacityconstexprbool empty()constnoexcept;constexpr size_type size()constnoexcept;constexpr size_type max_size()constnoexcept;constexpr size_type capacity()constnoexcept;constexprvoid resize(size_type sz,bool c=false);constexprvoid reserve(size_type n);constexprvoid shrink_to_fit(); // element accessconstexpr reference operator[](size_type n);constexpr const_reference operator[](size_type n)const;constexpr const_reference at(size_type n)const;constexpr reference at(size_type n);constexpr reference front();constexpr const_reference front()const;constexpr reference back();constexpr const_reference back()const; // modifierstemplate<class...Args>constexpr reference emplace_back(Args&&...args);constexprvoid push_back(constbool& x);template<container-compatible-range<bool> R>constexprvoid append_range(R&& rg);constexprvoid pop_back();template<class...Args>constexpr iterator emplace(const_iterator position, Args&&...args);constexpr iterator insert(const_iterator position,constbool& x);constexpr iterator insert(const_iterator position, size_type n,constbool& x);template<class InputIter>constexpr iterator insert(const_iterator position, InputIter first, InputIter last);template<container-compatible-range<bool> R>constexpr iterator insert_range(const_iterator position, R&& rg);constexpr iterator insert(const_iterator position, initializer_list<bool> il); constexpr iterator erase(const_iterator position);constexpr iterator erase(const_iterator first, const_iterator last);constexprvoid swap(vector&)noexcept( allocator_traits<Allocator>::propagate_on_container_swap::value|| allocator_traits<Allocator>::is_always_equal::value);staticconstexprvoid swap(reference x, reference y)noexcept;constexprvoid flip()noexcept;// flips all bitsconstexprvoid clear()noexcept;};}
namespace std{template<class T,class CharT> requires/*is-vector-bool-reference*/<T>struct formatter<T, CharT>{private: formatter<bool, CharT>/*underlying_*/;// exposition only public:template<class ParseContext>constexprtypename ParseContext::iterator parse(ParseContext& ctx); template<class FormatContext>typename FormatContext::iterator format(const T& ref, FormatContext& ctx)const;};}
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR | Applied to | Behavior as published | Correct behavior |
---|---|---|---|
LWG 4140 | C++98 | the synopsis contains a declaration of the default constructor ofstd::vector<bool, Alloc>::reference | removed the declaration |