標準ライブラリヘッダ <vector>
提供: cppreference.com
このヘッダはコンテナライブラリの一部です。
インクルード | ||
(C++20) | 三方比較演算子サポート | |
(C++11) | std::initializer_list クラステンプレート | |
クラス | ||
要素が隣接した動的な配列 (クラステンプレート) | ||
空間効率の良い動的なビット集合 (クラステンプレートの特殊化) | ||
(C++11) | std::vector<bool> に対するハッシュサポート (クラステンプレートの特殊化) | |
前方宣言 | ||
ヘッダ <functional> で定義 | ||
(C++11) | ハッシュ関数オブジェクト (クラステンプレート) | |
関数 | ||
(C++20で削除)(C++20で削除)(C++20で削除)(C++20で削除)(C++20で削除)(C++20) | vector 内の値を辞書的に比較します (関数テンプレート) | |
std::swap アルゴリズムの特殊化 (関数テンプレート) | ||
特定の基準を満たすすべての要素を削除します (関数テンプレート) | ||
範囲アクセス | ||
(C++11)(C++14) | コンテナまたは配列の先頭を指すイテレータを返します (関数) | |
(C++11)(C++14) | コンテナまたは配列の終端を指すイテレータを返します (関数) | |
(C++14) | コンテナまたは配列の先頭を指す逆イテレータを返します (関数) | |
(C++14) | コンテナまたは配列の終端を指す逆イテレータを返します (関数) | |
(C++17)(C++20) | コンテナまたは配列のサイズを返します (関数テンプレート) | |
(C++17) | コンテナが空かどうか調べます (関数) | |
(C++17) | ベースとなる配列を指すポインタを取得します (関数) |
[編集]概要
#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))); template<class T, class Allocator, class U>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); // class vector<bool>template<class Allocator>class vector<bool, Allocator>; // hash supporttemplate<class T>struct hash;template<class Allocator>struct hash<vector<bool, Allocator>>; namespace pmr {template<class T>using vector =std::vector<T, polymorphic_allocator<T>>;}}
[編集]クラステンプレート std::vector
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 InputIt>constexpr vector(InputIt first, InputIt last, const Allocator&= Allocator());constexpr vector(const vector& x);constexpr vector(vector&&)noexcept;constexpr vector(const vector&, const Allocator&);constexpr vector(vector&&, const 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 InputIt>constexprvoid assign(InputIt first, InputIt last);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; // capacity[[nodiscard]]constexprbool 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);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 InputIt>constexpr iterator insert(const_iterator position, InputIt first, InputIt last);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 InputIt, class Allocator = allocator</*iter-value-type*/<InputIt>>> vector(InputIt, InputIt, Allocator = Allocator())-> vector</*iter-value-type*/<InputIt>, Allocator>; // swaptemplate<class T, class Allocator>constexprvoid swap(vector<T, Allocator>& x, vector<T, Allocator>& y)noexcept(noexcept(x.swap(y)));}
[編集]クラステンプレート std::vector の bool に対する特殊化
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 {friendclass vector;constexpr reference()noexcept;public:constexpr reference(const reference&)=default;constexpr ~reference();constexpr operator bool()constnoexcept;constexpr reference& operator=(constbool x)noexcept;constexpr reference& operator=(const reference& x)noexcept;constexprvoid flip()noexcept;// flips the bit}; // construct/copy/destroyconstexpr vector(): vector(Allocator()){}constexprexplicit vector(const Allocator&);constexprexplicit vector(size_type n, const Allocator&= Allocator());constexpr vector(size_type n, constbool& value, const Allocator&= Allocator());template<class InputIt>constexpr vector(InputIt first, InputIt last, const Allocator&= Allocator());constexpr vector(const vector& x);constexpr vector(vector&& x);constexpr vector(const vector&, const Allocator&);constexpr vector(vector&&, const Allocator&);constexpr vector(initializer_list<bool>, const Allocator&= Allocator()));constexpr ~vector();constexpr vector& operator=(const vector& x);constexpr vector& operator=(vector&& x);constexpr vector& operator=(initializer_list<bool>);template<class InputIt>constexprvoid assign(InputIt first, InputIt last);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; // capacity[[nodiscard]]constexprbool 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);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 InputIt>constexpr iterator insert(const_iterator position, InputIt first, InputIt last);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&);constexprstaticvoid swap(reference x, reference y)noexcept;constexprvoid flip()noexcept;// flips all bitsconstexprvoid clear()noexcept;};}