
On Sat, Nov 24, 2012 at 1:25 AM, Steven Watanabe <watanabesj@gmail.com>wrote:
AMDG
On 11/23/2012 02:55 PM, Gottlob Frege wrote:
On Fri, Nov 23, 2012 at 7:17 AM, Olaf van der Spek <ml@vdspek.org> wrote:
A string_ref that's not required to be null-terminated is far more useful.
It does (to me at least) raise the question of whether string_ref is the correct name, as it is missing what might be seen as a fundamental aspect of strings - null termination.
fundamental? hardly. std::string is not guaranteed to be null terminated.
Guaranteed (almost) since C++11. c_str() and data() now *mean the same thing*, and s[s.size()] returned null even in C++03. The only thing that is not guaranteed is that *(&s[0] + s.size()) is null. Anyway the point is that you can retrieve a null terminated string from std::string in constant time, without copying anything. So it is practically null terminated.
Besides, if you want a null-terminated string without ownership, const char* works just fine.
It does not, as you cannot implicitly convert std::string (or anything else suitable) to const char*. -- Yakov