This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of CD1 status.

259. basic_string::operator[] and const correctness

Section: 23.4.3.5 [string.capacity] Status: CD1 Submitter: Chris Newton Opened: 2000-08-27 Last modified: 2016-01-28

Priority: Not Prioritized

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)".