After reading through the description about std::basic_string on cppreference, I'm uncertain about the following two questions regarding the underlying storage of std::basic_string:
1) Since C++11, does the contiguity of std::basic_string extends to the terminating null character? Note that str[str.size()] returns a reference to a terminating null character. But I want to make sure whether this is the one after str[str.size() - 1].
2) Since C++11, data() and c_str() become equivalent. But does it hold that data() == c_str() == &front()?
Any quotation from the standard would be appreciated.
This effectively requires that the terminating
NULbe stored contiguously together with the character sequence (it forces an additional requirement onoperator[]thats[s.size()]not do anything fancy, though the plain text of 21.4.5 appears to give it some latitude).It also explicitly requires that
s.c_str() == &s[0], which in turn means thats.c_str() == &s.front()(front()is defined asoperator[](0)).