According to this answer, an internal buffer of std::string
is not guaranteed to be contiguous under pre-C++11 standards. (Albeit almost all implementations use contiguous memory)
This means, technically, accessing a nth(n > 0?) element of a return value of string::data()
or string::c_str()
causes an undefined behavior. Is this correct?
std::string str = "Hello, World!"
str.c_str()[1]; // Which is equivalent to *(str.c_str() + 1), therefore UB?