Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > vector::reserve() with value less than current size().

Reply
Thread Tools

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

 
 
jason.cipriani@gmail.com
Guest
Posts: n/a
 
      11-19-2008
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
 
Reply With Quote
 
 
 
 
Joe Gottman
Guest
Posts: n/a
 
      11-19-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) 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
 
Reply With Quote
 
 
 
 
Salt_Peter
Guest
Posts: n/a
 
      11-19-2008
On Nov 18, 8:25 pm, "(E-Mail Removed)"
<(E-Mail Removed)> 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


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.

 
Reply With Quote
 
jason.cipriani@gmail.com
Guest
Posts: n/a
 
      11-19-2008
On Nov 18, 8:48*pm, Joe Gottman <(E-Mail Removed)> wrote:
> (E-Mail Removed) 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.

Jason
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Include header files in quotes or less-than greater-than signs? Dwight Army of Champions C++ 4 03-17-2010 06:39 PM
Graeter than or less than bbawa1@yahoo.com ASP .Net 4 06-21-2007 08:03 PM
regex problem: 'greater than' 'less than' and 'equals' not matching! falcon Java 10 02-24-2006 01:23 PM
Question: How to force a function to use the value of a variable when it's given rather than the current value of it joltman Javascript 2 09-29-2005 12:00 AM
Finding "last node with value less than" with XPath Scott W Gifford XML 7 08-15-2005 06:45 PM



Advertisments