I had heard that C++11 was going to require strings to be allocated in contiguous memory. I even thought I saw a stack overflow question on it, but I can\'t seem to
Section 21.4.1.5 of the 2011 standard states:
The char-like objects in a
basic_stringobject shall be stored contiguously. That is, for anybasic_stringobjects, the identity&*(s.begin() + n) == &*s.begin() + nshall hold for all values ofnsuch that0 <= n < s.size().
The two parts of the identity expression are
begin() iterator, advance by n, then dereference and take the address of the resulting element.begin() iterator, dereference and take the address of the resulting element. Add n to this pointer.Since both are required to be identical, this enforces contiguous storage; that is, the iterator cannot move over any non-contiguous storage without violating this requirement.