19
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【C++】STLコンテナ関数一覧

19
Last updated at Posted at 2015-11-18

STLコンテナの関数を機能単位で整理

function string vector list map 概要
reserve 〇 〇 初期化:capacity変更
shrink_to_fit 〇 〇 初期化:capacityをsizeまで縮小
assign 〇 〇 初期化:値付き初期化
resize 〇 〇 〇 初期化:要素数の変更
capacity 〇 〇 確認:capacityサイズ
size 〇 〇 〇 〇 確認:要素サイズ
length 〇 確認:要素サイズ(sizeと同じ)
max_size 〇 〇 〇 〇 確認:格納可能な最大の要素数
npos 〇 確認:システムが扱える文字列の最大長+1(findで見つからなかった場合の返り値)
count 〇 確認:キーが一致する要素数
[] 〇 〇 〇 〇 参照:指定位置(キー)
at 〇 〇 参照:指定位置
front 〇 〇 〇 参照:先頭
back 〇 〇 〇 参照:末尾
begin 〇 〇 〇 〇 iterator:先頭
end 〇 〇 〇 〇 iterator:末尾の次
rbegin 〇 〇 〇 〇 iterator:末尾(逆順)
rend 〇 〇 〇 〇 iterator:先頭の前 (逆順)
cbegin 〇 〇 〇 〇 iterator:先頭(読取り専用)
cend 〇 〇 〇 〇 iterator:末尾の次(読取り専用)
crbegin 〇 〇 〇 〇 iterator:末尾(読取り専用、逆順)
crend 〇 〇 〇 〇 iterator:先頭の前(読取り専用、逆順)
equal_range 〇 iterator:キーが一致する要素群の先頭と末尾
upper_bound 〇 iterator:キーが一致する要素群の先頭
lower_bound 〇 iterator:キーが一致する要素群の末尾
find 〇 iterator:キーにマッチした最初の要素
find 〇 index:単語が最初にマッチした位置
find_first_not_of 〇 index:単語中の文字が最初にマッチしなかった位置
find_first_of 〇 index:単語中の文字が最初にマッチした位置
rfind 〇 index:単語が最後にマッチした位置
find_last_not_of 〇 index:単語中の文字が最後にマッチしなかった位置
find_last_of 〇 index:単語中の文字が最後にマッチした位置
substr 〇 値:指定範囲
== 〇 〇 〇 〇 比較:等しければtrue
!= 〇 〇 〇 〇 比較:異なっていればture
< 〇 〇 〇 〇 比較:A<Bならばtrue
> 〇 〇 〇 〇 比較:A>Bならばtrue
<= 〇 〇 〇 〇 比較:A<=Bならばtrue
>= 〇 〇 〇 〇 比較:A>=Bならばtrue
empty 〇 〇 〇 〇 比較:空ならtrue
compare 〇 比較:辞書順比較
= 〇 〇 〇 〇 変更:代入(全置換)
replace 〇 変更:文字列置換
copy 〇 変更:文字列コピー
swap 〇 〇 〇 〇 変更:要素の交換
sort 〇 変更:リストのソート
reverse 〇 変更:リストの反転
insert 〇 〇 〇 〇 挿入:指定位置
push_front 〇 挿入:先頭
push_back 〇 〇 〇 挿入:末尾
append 〇 挿入:末尾
+= 〇 挿入:末尾
emplace 〇 〇 〇 挿入:指定位置(要素構築)
emplace_hint 〇 挿入:指定位置(要素構築)
emplace_front 〇 挿入:先頭(要素構築)
emplace_back 〇 〇 挿入:末尾(要素構築)
+ 〇 連結
splice 〇 移動:指定位置に要素を移動
merge 〇 移動:先頭要素から大小比較をしながら要素を移動
erase 〇 〇 〇 〇 削除:指定位置(キー)の要素
remove 〇 削除:値が一致した要素
remove_if 〇 削除:条件が一致した要素
pop_front 〇 削除:先頭要素
pop_back 〇 〇 〇 削除:末尾要素
unique 〇 削除:重複要素
clear 〇 〇 〇 〇 削除:全要素
data 〇 配列表現にした場合の先頭ポインタ
data 〇 配列表現にした場合の先頭ポインタ※制約あり
c_str 〇 型変換:char型文字列
get_allocator 〇 〇 〇 〇 取得:アロケータオブジェクト

【参考】
増田 智明. C/C++辞典―Windows/Linux/UNIX対応. 秀和システム, 2010, pp.427-543
cpprefjp - C++日本語リファレンス/リファレンス/string/basic_string
cpprefjp - C++日本語リファレンス/リファレンス/vector
cpprefjp - C++日本語リファレンス/リファレンス/list
cpprefjp - C++日本語リファレンス/リファレンス/map

19
15
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?