Monday, March 10, 2014

Which one(s) of the following std::vector's member functions has the possibility/authority to reduce a vector's capacity?

Newsgroup: comp.lang.c++

Subject: Which one(s) of the following std::vector's member functions has the possibility/authority to reduce a vector's capacity?

From: goodbyeera@...

Date: Sun, 9 Mar 2014 19:11:23 -0700 (PDT)



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







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/NRcatl

View all the progranning help forums at:

http://ift.tt/1dP9txN

No comments:

Post a Comment