Topic: reserve() and capacity()


Author: Nico Josuttis <nico@bredex.de>
Date: 1996/04/02
Raw View
Two "container" have reserve() and capacity():
 string and vector.
For both first a simple hint:
The january draft says, that
    It is guaranteed that no
    reallocation takes place during the  insertions  that  happen  after
    reserve()  takes  place  till  the  time when the size of the vector/string

    reaches the size specified by reserve().
First "reaching" the size should also guarantee that no reallocation takes
place. I think "exceeds" would be the correct naming here.

But I have deeper questions:
For vectors for every member function it is documented how it unvalidates
iterators and references.
Following that I would guess that
 a) vector capacity in general can't shrink
 b) iterators stay valid even if following elements get destroyed
On the other hand the standard says that
 a) no reallocation takes place during the  INSERTIONS ...
 b) The reference returned by the non-const version is invalid after any
    subsequent call to c_str(), data(), or any non-const member function
    for the object.
    (only for string, the vector version is missing)

So my questions are:
 - What is right for vector and string?
 - How long stay iterators and references valid for both?
 - May the capacity() shrink for both?

Thanks in advance
--------
Nico                             address: BREDEX GmbH
email:   nico@bredex.de                   Nicolai Josuttis
                                          Fallersleber-Tor-Wall 23
phone:   +49 531 24330-0                  D-38100 Braunschweig
fax:     +49 531 24330-99                 Germany
--------
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]