By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,948 Members | 1,215 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,948 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Nov 19 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
ja************@gmail.com wrote:
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
Nov 19 '08 #2

P: n/a
On Nov 18, 8:25 pm, "jason.cipri...@gmail.com"
<jason.cipri...@gmail.comwrote:
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.

Nov 19 '08 #3

P: n/a
On Nov 18, 8:48*pm, Joe Gottman <jgott...@carolina.rr.comwrote:
jason.cipri...@gmail.com wrote:
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.
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
Nov 19 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.