Consider the following from C++11:
[C++11: 21.4.5]:basic_stringelement access [string.access]const_reference operator[](size_type pos) const; reference operator[](size_type pos);1 Requires:
pos <= size().2 Returns:
*(begin() + pos)ifpos < size(), otherwise a reference to an object of typeTwith valuecharT(); the referenced value shall not be modified.3 Throws: Nothing.
4 Complexity: constant time.
This means either:
- The referenced value in the
pos == size()case shall not be modified, or - In any case, the referenced value returned by
op[]shall not be modified, even for the non-constoverload.
The second scenario seems completely ridiculous, but I think it's what the wording most strongly implies.
Can we modify what we get from std::string::op[], or not? And is this not rather ambiguous wording?