コンテナ コンテナ共通メンバ関数 イテレータ 挿入 専用メンバ

コンテナ
コンテナ共通メンバ関数
イテレータ
最後の要素の参照を返す
T& back(); const T& back() const;
先頭/末尾の要素を指すイテレータを返す
iterator begin(); / const_iterator begin() const;
iterator end(); / const_iterator end() const;
先頭/末尾の要素を指す逆イテレータを返す
reverse_iterator rbegin();
const_reverse_iterator rbegin() const;
reverse_iterator rend();
const_reverse_iterator rend() const;
posの位置にxを挿入
iterator insert(iterator pos, const T& x);
posの位置にn個のxを挿入
iterator insert(iterator pos,size_t n,const T &x);
posの位置に[first, last)を挿入
template<class Input>
void insert(iterator pos, Input first, Input last);
サイズ
現サイズ(== end() - begin() 要素数)
size_t size() const;
空かどうか
bool empty() const;
最大サイズ(確保可能な領域の大きさ/要素の大きさ)
size_t max_size() const;
削除
posの要素を削除し次の要素のイテレータを返す
iterator erase(itearator pos);
[first, last)を削除し次の要素のイテレータを返す
iterator erase(iterator first, iterator last);
全削除
void clear();
その他
xと中身を入れ替え
void swap(vector<T, Alloc>& x);
アロケータの取得
alloc_type get_allocator() const;
非メンバ関数
x != y
template <class T>
bool operator!=(const Cont <T>& lhs,
const Cont<T>& rhs);
x == y
template <class T>
bool operator==(const Cont <T>& lhs,
const Cont<T>& rhs);
x<y
template <class T>
bool operator<(const Cont <T>& lhs,
const Cont<T>& rhs);
x <= y
template <class T>
bool operator<=(const Cont <T>& lhs,
const Cont<T>& rhs);
x>y
template <class T>
bool operator>(const Cont <T>& lhs,
const Cont<T>& rhs);
x >= y
template <class T>
bool operator>=(const Cont <T>& lhs,
const Cont<T>& rhs);
swap
void swap(Cont<T>& lhs, Cont<T>& rhs);
<vector><list><deque>共通メンバ関数
テンプレート定義
template <class T, class Alloc = alloc<T> >
class Cont;
コンストラクタ/デストラクタ
ディフォルトコンストラクタ
explicit Cont(const Alloc& alloc=Alloc());
n個のvalueで初期化
explicit Cont(size_t n, const T& value = T(),
const Alloc& alloc=Alloc());
イテレータで初期化
template <class InputItr>
Cont(InputItr first, InputItr last,
const Alloc& alloc = Alloc());
コピーコンストラクタ
Cont(const Cont& x);
デストラクタ
~Cont();
代入
コピー代入
Cont<T>& operator=(const Cont& x);
n個のvalueを代入
void assign(size_t n, const T& value);
イテレータで代入
template<class InputItr>
assign(InputItr first, InputItr last);
サイズ
大きさ変更(拡張分はxで初期化, 領域は解放しない)
void resize(size_t new_size, T& x = T());
挿入
<vector>専用メンバ関数
サイズ
確保したメモリ量(<vector>のみ)
size_t capacity() const;
n個分のメモリを確保する(<vector>のみ)
void reserve(size_t n);
要素の参照
n番目の要素を参照
T& operator[](size_t n)
const T& operator[](size_t n) const;
T& at(size_t n)
const T& at(size_t n) const;
要素の追加・削除
末尾に要素を追加/削除
void push_back(const T& x); void pop_back();
<deque>専用メンバ関数
要素の参照
n番目の要素を参照
T& operator[](size_t n)
const T& operator[](size_t n) const;
T& at(size_t n)
const T& at(size_t n) const;
要素の追加・削除
末尾に要素を追加/削除
void push_back(const T& x); void pop_back();
先頭に要素を追加/削除
void push_front(const T& x) / void pop_front()
<list>専用メンバ関数
要素の追加・削除
末尾に要素を追加/削除
void push_back(const T& x); void pop_back();
先頭に要素を追加/削除
void push_front(const T& x) / void pop_front()
アルゴリズム
値valueを持つ要素を削除 / 条件付き削除
void remove(const T &value);
template<class Pred> void remove_if(Pred p);
ユニーク
void unique();
template<class BinaryPred>
void unique(BinaryPred bp);
マージ
void merge(list<T, Alloc>&x);
template <class Compare>
void merge(list<T, Alloc>&x, Compare comp);
ソート
void sort();
template <class Compare>
void sort(Compare comp);
リバース
void reverse();
<map><set>連想コンテナ共通メンバ関数
テンプレート定義
set,multiset
template <class Key, class Comp=less<Key>,
class Alloc=alloc<Key> > set;
map,multimap
template <class Key, class T, class Comp=less<Key>
class Alloc=alloc<Key> > map;
コンストラクタ/デストラクタ
ディフォルトコンストラクタ
explicit Cont(const Comp& comp=Comp(),
const Alloc& alloc=Alloc());
イテレータで初期化
template <class InputItr>
Cont(InputItr first, InputItr last,
const Comp &comp = Comp(),
const Alloc& alloc = Alloc());
コピーコンストラクタ
Cont(const Cont& x);
デストラクタ
~Cont();
その他
比較関数の取得
key_comp key_comp() const;
value_comp value_comp() const;
要素の参照
挿入
先頭の要素の参照を返す
T& front(); const T& front() const;
挿入 (set, mapの場合 既に値がある場合はfalseを返す)
pair<iterator, bool> map::insert(const value_type &x);
挿入 (multimap, multisetの場合 失敗せずiteratorだけを返す)
iterator multimap::insert(const value_type& x);
posを検索開始位置としてxを挿入
pair<iterator, bool> map::insert(iterator pos,
const value_type &x);
iterator multimap::insert(iterator pos,
const value_type &x);
posの位置に[first, last)を挿入
template<class Input>
void insert(Input first, Input last);
検索
xをキーにもつ要素のイテレータを返す
iterator find(const key_type& x);
const_iterator find(const key_type& x) const;
xをキーに持つ要素の数を返す
size_t count(const key_type& x) const;
xをキーに持つ最初の要素を指すイテレータを返す
iterator lower_bound(const key_type& x);
const_iterator lower_bound(const key_type& x) const;
xをキーに持つ最後の次の要素を指すイテレータを返す
iterator upper_bound(const key_type& x);
const_iterator upper_bound(const key_type& x) const;
xをキーに持つ範囲のイテレータのペアを返す
pair<iterator, iterator> equal_range(const key_type& x);
pair<const_iterator, const_iterator>
equal_range(const key_type& x) const;
キーに対応する要素を参照(mapのみ)
T& operator[](const key_type& k);
<queue><stack>定義(コンテナアダプタ)
テンプレート定義
キュー
template <class T, class Cont = deque<T> >
class queue;
スタック
template <class T, class Cont = deque<T> >
class stack;
優先順位付きキュー
template <class T, class Cont = vector<T>
class Compare=less<Cont::value_type> >
class priority_queue;
コンストラクタ/デストラクタ
キュー(ディフォルトコンストラクタ)
explicit queue(const Cont& = Cont());
スタック(ディフォルトコンストラクタ)
explicit stack(const Cont& = Cont());
優先順位付きキュー(ディフォルトコンストラクタ)
explicit priority_queue(
const Compare& x=Compare(),
const Cont& = Cont());
優先順位付きキューのイテレータによる初期化
template<class InputItr>
priority_queue(InputItr first, InputItr last,
const Compare& x=Compare(),
const Cont& = Cont());
サイズ
現サイズ(== end() - begin() 要素数)
size_t size() const;
空かどうか
bool empty() const;
要素の追加・削除・参照
要素の追加・削除削除
void push(const T& x); / void pop();
先頭の要素を返す(stack, priority_queueのみ)
T& top(); / const T& top() const;
先頭の要素を返す(queueのみ)
T& front(); / const T& front() const;
末尾の要素を返す
T& back(); / const T& back() const;
非メンバ関数
各種比較関数(定義はdequeと同一)
(queue, stackのみ)
x != y
template <class T>
bool operator!=(const Cont <T>& lhs,
const Cont<T>& rhs);
x == y
template <class T>
bool operator==(const Cont <T>& lhs,
const Cont<T>& rhs);
x<y
template <class T>
bool operator<(const Cont <T>& lhs,
const Cont<T>& rhs);
x <= y
template <class T>
bool operator<=(const Cont <T>& lhs,
const Cont<T>& rhs);
x>y
template <class T>
bool operator>(const Cont <T>& lhs,
const Cont<T>& rhs);
x >= y
template <class T>
bool operator>=(const Cont <T>& lhs,
const Cont<T>& rhs);