This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [v3] basic_string::reserve() shrink-to-fit?
On Thu, Dec 11, 2003 at 09:35:17AM -0800, Nathan Myers wrote:
> On Thu, Dec 11, 2003 at 05:20:20PM +0000, Jonathan Wakely wrote:
> > I'll prepare a FAQ entry tonight if noone beats me too it.
>
> For vector, the shorter
>
> std::vector<T>(v).swap(v);
>
> is preferred. I.e. vector isn't copy-on-write, so a regular copy
> suffices to construct the temporary.
Paolo and Neil hasten to remind me that I recollect wrongly about
std::string::reserve. I should have looked it up, because memory does
fade, and one can't be everywhere at once, and who knows what evil
lurks in the sub-groups of the LWG?
So, the FAQ is really only about vector, but deserves to be there
not less.
Nathan Myers
ncm-nospam@cantrip.org