Title
String::npos vs. string::max_size()
Status
tc1
Section
[basic.string]
Submitter
Nico Josuttis

Created on 1998-09-29.00:00:00 last changed 164 months ago

Messages

Date: 2010-10-21.18:28:33

Rationale:

The LWG believes length_error is the correct exception to throw.

Date: 2010-10-21.18:28:33

Proposed resolution:

After [basic.string] paragraph 4 ("The functions described in this clause...") add a new paragraph:

For any string operation, if as a result of the operation, size() would exceed max_size() then the operation throws length_error.

Date: 1998-09-29.00:00:00

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.

History
Date User Action Args
2010-10-21 18:28:33adminsetmessages: + msg191
2010-10-21 18:28:33adminsetmessages: + msg190
1998-09-29 00:00:00admincreate