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 11:03:05AM -0800, Nathan Myers wrote:
> 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.
OK, I have a
5.9 How do I make std::vector<T>::capacity() == std::vector<T>::size()?
FAQ entry ready. Will post for comments shortly.
How about a "6. Shrink-to-fit strings" entry in 21_strings/howto.html
that documents the fact that libstdc++ does/will support shrink requests
from 3.4, but not before, and suggesting the alternative below ?
std::string(str.data(), str.size()).swap(str);
--
I don't pretend to be an expert on intellectual property law, but I do
know one thing. If a music industry executive claims I should agree with
their agenda because it will make me more money, I put my hand on my wallet
... and check it after they leave, just to make sure nothing's missing.
- Janis Ian <http://www.janisian.com/article-internet_debacle.html>