C++ Logo

std-proposals

Advanced search

Re: Breaking change - std::string should implicitly accept literals but not general c strings

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Mon, 17 Aug 2020 10:13:12 -0400
On Sun, Aug 16, 2020 at 5:13 PM Thiago Macieira via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> On Sunday, 16 August 2020 14:07:47 PDT Matthew Fioravante via Std-Proposals
> wrote:
> > At least in this particular case, it is also pretty rare. The most common
> > usage that comes to mind is the snprintf idiom above, but that is going to
> > be obsolete when we get fmt in the standard.
>
> I'd really welcome a low-level type that only binds to literals, but not const
> char* or stack arrays. That would indeed allow for zero-copy.

While I like the idea, the downside is that you also want that type to
be able to be used as an NTTP in a template. And without it actually
being an array of characters, that's not possible (with C++20 at
least). Indeed, the standard states very plainly that you *cannot*
store a pointer to a string literal in anything that is used in an
NTTP. Likely due to some implementation issues around comparisons to
pointers to literals (since two equal literals aren't required to have
the same address) and name mangling.

Received on 2020-08-17 09:16:49