3 ms·
It seems[1] that since C++11 .data() and .c_str() are the same function. c_str() is also documented as having constant complexity. If it made a copy, wouldn't i
by thestoicattack 8y ago
It seems[1] that since C++11 .data() and .c_str() are the same function. c_str() is also documented as having constant complexity. If it made a copy, wouldn't it have to be linear?
[1] https://en.cppreference.com/w/cpp/string/basic_string/data https://en.cppreference.com/w/cpp/string/basic_string/data
- gpderetta 8y agoYes. Allocating on demand was a legal implementation before c++11. No standard library made use of the option and the latitude was removed in c++11. I think it is still allowed to null terminate on demand.
- hermitdev 8y agoIt doesn't have to make a copy. std::string is always null-terminated as of C++11.