vector::reserve() with value less than current size().

J

jason.cipriani

What is the official word on what happens if I call reserve() on an
std::vector, and specify a capacity that is less than the current
*size* (not capacity) of that vector? Is it supposed to resize() the
vector as well? Or just not modify anything?

Thanks,
Jason
 
J

Joe Gottman

What is the official word on what happens if I call reserve() on an
std::vector, and specify a capacity that is less than the current
*size* (not capacity) of that vector? Is it supposed to resize() the
vector as well? Or just not modify anything?

Thanks,
Jason

reserve() never reduces capacity; it just increases it. Therefore this
is a no-op.

Joe Gottman
 
S

Salt_Peter

What is the official word on what happens if I call reserve() on an
std::vector, and specify a capacity that is less than the current
*size* (not capacity) of that vector? Is it supposed to resize() the
vector as well? Or just not modify anything?

Thanks,
Jason

The size of the vector is irrelevant. If reserve's arguement is less
than or equal to its capacity, nothing happens. Swap the vector to
(maybe) change its capacity.
 
J

jason.cipriani

reserve() never reduces capacity; it just increases it.  Therefore this
is a no-op.

That's what I was looking for, thanks Joe and Salt_Peter.

Also, sorry, I'm looking now and it turns out that actually *is*
stated in the docs I was reading, it's just in a footnote that I
missed. :-o

Jason
 

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,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top