std::string::reserve vs std::vector::reserve

Peter Soetens peter.soetens@mech.kuleuven.be
Thu Jun 16 11:00:00 GMT 2005


Hi,

I do not have the Standard, but the "C++ Programming Language" by BS states 
that both string reserve and operator= behave 'like' vector's. Well, in GCC 
2.95, 3.2, 3.3,3.4 and 4.0, it doesn't (so I'm probably wrong...).

A vector keeps its reserved capacity after an assignment, a string doesn't. 

I know this is because of the COW implementation. In fact, the string gets the 
capacity of the original... How does the Standard define the correct 
behaviour ? Will one day vector behave likewise ?

A Test program is in attachment.

Peter Soetens
-- 
K.U.Leuven, Mechanical Engineering, Robotics Research Group
<http://www.orocos.org> Tel: +32 16 322772
-------------- next part --------------
A non-text attachment was scrubbed...
Name: string_capacity.cpp
Type: text/x-c++src
Size: 559 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20050616/9a089fc7/attachment.bin>


More information about the Libstdc++ mailing list