259. basic_string::operator[] and const correctness

Section: 24.3.2.4 [string.capacity] Status: CD1 Submitter: Chris Newton Opened: 2000-08-27 Last modified: 2016-02-10

Priority: Not Prioritized

View other active issues in [string.capacity].

View all other issues in [string.capacity].

View all issues with CD1 status.

Discussion:

Paraphrased from a message that Chris Newton posted to comp.std.c++:

The standard's description of basic_string<>::operator[] seems to violate const correctness.

The standard (21.3.4/1) says that "If pos < size(), returns data()[pos]." The types don't work. The return value of data() is const charT*, but operator[] has a non-const version whose return type is reference.

Proposed resolution:

In section 21.3.4, paragraph 1, change "data()[pos]" to "*(begin() + pos)".