This is the mail archive of the
libstdc++@sourceware.cygnus.com
mailing list for the libstdc++ project.
basic_string<>::reserve - patch
- To: libstdc++@sourceware.cygnus.com
- Subject: basic_string<>::reserve - patch
- From: Nathan Myers <ncm@best.com>
- Date: Wed, 30 Jun 1999 03:38:43 -0700 (PDT)
- Reply-To: libstdc++@sourceware.cygnus.com
> In reserve I added a check for _M_state too. Otherwise it would not have
> the expected behaviour if the string has enough storage reserved but
> it has reference copies.
Right, it would lazily clone, but the clone would not get the
reserved storage.
> BTW. In reserve we not check the __res_arg vlaue for a length_error.
> If max_size() is much less than npos we should.
> But I do not know if the standard allows reserve to throw
> a length_error. If not it means that max_size() must return a value
> very close to npos.
It is common to have (max_size() < npos/4), as in wstring.
I agree that it should throw before trying to allocate
too much storage, and that the check should be based on
character units rather than bytes, to avoid overflow
errors.
Nathan Myers
ncm@cantrip.org