G
goodbyeera
Which one(s) of the following std::vector's member functions has the possibility/authority to reduce a vector's capacity?
I have 5 member functions in question:
template <class T, class Allocator = allocator<T> >
class vector {
public:
vector<T,Allocator>& operator=(const vector<T,Allocator>& x);
vector<T,Allocator>& operator=(vector<T,Allocator>&& x);
vector& operator=(initializer_list<T>);
void assign(initializer_list<T>);
void clear() noexcept;
};
Notes:
- For assignments: Unlike vector::swap() which explicitly specifies exchanging both contents and capacity, I can't find reliable answers for the various forms of assignments.
- For std::assign(), there are 2 other overloads:
template <class InputIterator> void assign(InputIterator first, InputIterator last);
void assign(size_type n, const T& u);
And they are both explicitly defined in terms of calls to erase() and insert(), so it's guaranteed with no reduce in capacity. But for the overload taking an initializer_list as the argument, I can't find a reliable answer.
- For std::clear(), in C++03, it's explicitly defined in terms of erase(begin(),end()), so it's guaranteed with no reduce in capacity. I can't find equivalent definition in C++11 anymore.
Relevant excerpts from the standard are highly appreciated.
Thanks,
Goodbyeera
I have 5 member functions in question:
template <class T, class Allocator = allocator<T> >
class vector {
public:
vector<T,Allocator>& operator=(const vector<T,Allocator>& x);
vector<T,Allocator>& operator=(vector<T,Allocator>&& x);
vector& operator=(initializer_list<T>);
void assign(initializer_list<T>);
void clear() noexcept;
};
Notes:
- For assignments: Unlike vector::swap() which explicitly specifies exchanging both contents and capacity, I can't find reliable answers for the various forms of assignments.
- For std::assign(), there are 2 other overloads:
template <class InputIterator> void assign(InputIterator first, InputIterator last);
void assign(size_type n, const T& u);
And they are both explicitly defined in terms of calls to erase() and insert(), so it's guaranteed with no reduce in capacity. But for the overload taking an initializer_list as the argument, I can't find a reliable answer.
- For std::clear(), in C++03, it's explicitly defined in terms of erase(begin(),end()), so it's guaranteed with no reduce in capacity. I can't find equivalent definition in C++11 anymore.
Relevant excerpts from the standard are highly appreciated.
Thanks,
Goodbyeera