STLのソースコードを読んでみよう!~std::vector編~
- 11. STLとは
• Standard Template Libraryの略
• C++における標準ライブラリの一部
主にデータ構造・アルゴリズムを提供する
(可変長配列、連結リスト、集合など)
• テンプレート機構により、だいたいどんな型に
対しても上記の機構が利用できる
std::list<int> // 整数の連結リスト
std::list<double> // 浮動小数点数の
- 13. std::vectorとは
• 可変長配列のクラス
vec = std::vector<double>(24);
vec.resize(11);
• 添字を指定しての要素アクセスは
定数時間で完了
vec[3] = 3776.0;
• ただし配列サイズの変更は、配列サイズに
比例した時間が(最悪ケースで)必要
vec.push_back(3776.0);
- 20. ファイル構成(抜粋)
• vector
• bits/
• allocator.h
• range_access.h
• stl_algobase.h
• stl_bvector.h
• stl_construct.h
• stl_uninitialized.h
• stl_vector.h
- 21. ファイル構成(抜粋)
• vector
• bits/
• allocator.h
• range_access.h
• stl_algobase.h
• stl_bvector.h
• stl_construct.h
• stl_uninitialized.h
• stl_vector.h
- 24. コンストラクタ
std::vectorのコンストラクタは結構多い
explicit vector(const Allocator& a=Allocator());
explicit vector(size_type n);
explicit vector(size_type n, const T& value,
const Allocator& a=Allocator());
template <class InputIter>
vector(InputIter first, InputIter last,
const Allocator& a=Allocator());
vector(const vector& x);
// C++11
vector(const vector& x, const Allocator& a);
vector(vector && x);
vector(vector && x, const Allocator& a);
vector(initializer_list<T> il, const Allocator& a=Allocator());
http://sites.google.com/site/cpprefjp/reference/vector/vector
- 25. コンストラクタ
std::vectorのコンストラクタは結構多い
explicit vector(const Allocator& a=Allocator());
explicit vector(size_type n);
explicit vector(size_type n, const T& value,
const Allocator& a=Allocator());
template <class InputIter>
vector(InputIter first, InputIter last,
const Allocator& a=Allocator());
vector(const vector& x);
// C++11
vector(const vector& x, const Allocator& a);
vector(vector && x);
vector(vector && x, const Allocator& a);
vector(initializer_list<T> il, const Allocator& a=Allocator());
http://sites.google.com/site/cpprefjp/reference/vector/vector
- 28. コンストラクタ
コンストラクタが多い
explicit vector(const Allocator& a=Allocator());
explicit vector(size_type n);
explicit vector(size_type n, const T& value,
const Allocator& a=Allocator());
template <class InputIter>
vector(InputIter first, InputIter last,
const Allocator& a=Allocator());
vector(const vector& x);
// C++11
vector(const vector& x, const Allocator& a);
vector(vector&& x);
vector(vector&& x, const Allocator& a);
vector(initializer_list<T> il, const Allocator& a=Allocator());