Connecting Tech Pros Worldwide Forums | Help | Site Map

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

jason.cipriani@gmail.com
Guest
 
Posts: n/a
#1: Nov 19 '08
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

Joe Gottman
Guest
 
Posts: n/a
#2: Nov 19 '08

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


jason.cipriani@gmail.com wrote:
Quote:
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
Salt_Peter
Guest
 
Posts: n/a
#3: Nov 19 '08

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


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

jason.cipriani@gmail.com
Guest
 
Posts: n/a
#4: Nov 19 '08

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


On Nov 18, 8:48*pm, Joe Gottman <jgott...@carolina.rr.comwrote:
Quote:
jason.cipri...@gmail.com wrote:
Quote:
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?
>
Quote:
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
Closed Thread


Similar C / C++ bytes