explicit list (const allocator_type& alloc = allocator_type());
fill (2)
explicit list (size_type n, const value_type& val = value_type(),
const allocator_type& alloc = allocator_type());
range (3)
template <class InputIterator>
list (InputIterator first, InputIterator last,
const allocator_type& alloc = allocator_type());
copy (4)
list (const list& x);
C++11;
default (1)
explicit list (const allocator_type& alloc = allocator_type());
fill (2)
explicit list (size_type n);
list (size_type n, const value_type& val,
const allocator_type& alloc = allocator_type());
range (3)
template <class InputIterator>
list (InputIterator first, InputIterator last,
const allocator_type& alloc = allocator_type());
copy (4)
list (const list& x);
list (const list& x, const allocator_type& alloc);
move (5)
list (list&& x);
list (list&& x, const allocator_type& alloc);
initializer list (6)
list (initializer_list<value_type> il,
const allocator_type& alloc = allocator_type());
C++14:
default (1)
list();
explicit list (const allocator_type& alloc);
fill (2)
explicit list (size_type n, const allocator_type& alloc = allocator_type());
list (size_type n, const value_type& val,
const allocator_type& alloc = allocator_type());
range (3)
template <class InputIterator>
list (InputIterator first, InputIterator last,
const allocator_type& alloc = allocator_type());
copy (4)
list (const list& x);
list (const list& x, const allocator_type& alloc);
move (5)
list (list&& x);
list (list&& x, const allocator_type& alloc);
initializer list (6)
list (initializer_list<value_type> il,
const allocator_type& alloc = allocator_type());
用来复制或获取的一个相同类型的 list 对象(具有相同的类模板参数T和Alloc),其内容被复制或获取。
il
一个initializer_list对象。
这些对象是由初始化列表声明符自动构造的。
成员类型value_type是容器中元素的类型,在 list 中定义为其第一个模板形参(T)的别名。
☣ 示例
// constructing lists
#include <iostream>
#include <list>
int main ()
{
// constructors used in the same order as described above:
std::list<int> first; // empty list of ints
std::list<int> second (4,100); // four ints with value 100
std::list<int> third (second.begin(),second.end()); // iterating through second
std::list<int> fourth (third); // a copy of third
// the iterator constructor can also be used to construct from arrays:
int myints[] = {16,2,77,29};
std::list<int> fifth (myints, myints + sizeof(myints) / sizeof(int) );
std::cout << "The contents of fifth are: ";
for (std::list<int>::iterator it = fifth.begin(); it != fifth.end(); it++)
std::cout << *it << ' ';
std::cout << '\n';
return 0;
}