Subject: Re: [boost] Heads up - string_ref landing
From: Yakov Galka (ybungalobill_at_[hidden])
Date: 2012-11-24 02:42:05
On Sat, Nov 24, 2012 at 1:25 AM, Steven Watanabe <watanabesj_at_[hidden]>wrote:
> On 11/23/2012 02:55 PM, Gottlob Frege wrote:
> > On Fri, Nov 23, 2012 at 7:17 AM, Olaf van der Spek <ml_at_[hidden]>
> >> A string_ref that's not required to be null-terminated is far more
> > 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 + 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*.