一个向量被定义为
template < class T, class Alloc = allocator<T> > class vector;
每个向量构造函数(或每种类型的一个重载)都有一个分配器重载,默认构造函数也有一个。分配器已在类模板中指定。构造函数分配器有什么用?
来自http://www.cplusplus.com/reference/vector/vector/vector/
default (1)
explicit vector (const allocator_type& alloc = allocator_type());
fill (2)
explicit vector (size_type n);
vector (size_type n, const value_type& val,
const allocator_type& alloc = allocator_type());
range (3)
template <class InputIterator>
vector (InputIterator first, InputIterator last,
const allocator_type& alloc = allocator_type());
copy (4)
vector (const vector& x);
vector (const vector& x, const allocator_type& alloc);
move (5)
vector (vector&& x);
vector (vector&& x, const allocator_type& alloc);
initializer list (6)
vector (initializer_list<value_type> il,
const allocator_type& alloc = allocator_type());