basic_string<>::max_size - only 1MB?

Ryszard Kabatek rysio@rumcajs.chemie.uni-halle.de
Thu Jun 24 07:19:00 GMT 1999


On Thu, 24 Jun 1999, Nicolai Josuttis wrote:

>  Many string member functions throw if size is getting or exceeding npos.
> However, I wonder why they don't throw  if size is getting or exceeding
> max_size() instead of npos. May be
>  npos is known at compile time, while max_size() is known at runtime. However,
> what happens if size exceeds
>  max_size() but not npos, then ? It seems the standard lacks some
>  clarifications here. 
> 
> The proposed solution will probably be that in this case length_error gets
> thrown.

A logical value for npos is max_size() + 1.
Throwing in a case if a requierd length reaches or exceedes npos 
is then compatible with exceeding max_size().


BTW. Must the value of npos be size_type(-1) ?


Ryszard Kabatek
Martin-Luther University Halle-Wittenberg, Department of Physical Chemistry
Geusaer Str. 88, 06217 Merseburg, Germany
Tel. +49 3461 46 2487 (2466) Fax. +49 3461 46 2129



More information about the Libstdc++ mailing list