STL容器分为三部分
- 顺序容器
- 关联容器
- 容器适配器
顺序容器
vector(常见的顺序容器)
(1)default 默认构造函数
vector();
explicit vector (const allocator_type& alloc);//该函数为vector()的一个编译器解释
(2)fill
explicit vector (size_type n, const allocator_type& alloc = allocator_type());
vector (size_type n, const value_type& val,const allocator_type& alloc = allocator_type());
(3)range 迭代器方式初始化
template vector (InputIterator first, InputIterator last,const allocator_type& alloc = allocator_type());
(4) copy 赋值构造函数
vector (const vector& x);
vector (const vector& x, const allocator_type& alloc);
(5)move 移动构造函数
vector (vector&& x); vector
(vector&& x, const allocator_type& alloc);
(6)initializer list 初始化列表
vector (initializer_list<value_type> il, const allocator_type& alloc = allocator_type());
(1)空容器构造函数(默认构造函数)
vector();
构造一个没有元素的空容器。
std::vector<int> value;//为空,里面什么都没有
(2)填充构造函数
explicit vector (size_type n, const allocator_type& alloc = allocator_type());
构造一个包含n个元素的容器。 每个元素都是val的副本(如果提供,可以不提供)。
std::vector<std::string> words4(5, "Mo");
std::cout << "words4: " << words4 << '\n';
(3)范围构造器
template vector (InputIterator first, InputIterator last,const allocator_type& alloc = allocator_type());
构造一个包含与范围[first,last)一样多的元素的容器,每个元素都从该范围内的相应元素以相同顺序进行位置构造。
std::vector<std::string> words2(words1.begin(), words1.end());
std::cout << "words2: " << words2 << '\n';
(4)赋值构造函数(并用分配器复制)
vector (const vector& x);
以相同的顺序构造一个容器,其中包含x中每个元素的副本。
std::vector<std::string> words3