Which one(s) of the following std::vector's member functions has thepossibility/authority to reduce

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
 
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

Just found in table 100 of the standard that a.assign(il) is defined as a.assign(il.begin(), il.end()), where il designates an object of type initializer_list<value_type>, so std::assign() should be removed from my question list. Sorry for the overlook.

Thanks,
Goodbyeera
 
Ö

Öö Tiib

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);

It can reduce capacity of target object and implementations do.
vector<T,Allocator>& operator=(vector<T,Allocator>&& x);

It can (and does) reduce capacity of both target and x if it wants to.
vector& operator=(initializer_list<T>);

I'm incapable to find any relevant legaleze. Those lists are new,
better safe than sorry.
void assign(initializer_list<T>);

It can't reduce capacity of target but may increase it. New too,
so better to be careful.
void clear() noexcept;

Capacity of target object may not change by standard but there are some
known old defective implementations that may change it.
};
....

Relevant excerpts from the standard are highly appreciated.

Search engines can likely find those from some previous discussions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,697
Latest member
AugustNabo

Latest Threads

Top