C++ Logo

std-proposals

Advanced search

Re: [std-proposals] [Idea] Null-terminated string view (c_str_view / c_wstr_view) – a simpler alternative/complement to zstring_view

From: Ell <ell.ell.se_at_[hidden]>
Date: Wed, 04 Feb 2026 16:15:59 +0000
On Wednesday, February 4th, 2026 at 3:07 AM, Thiago Macieira <thiago_at_[hidden]> wrote:

>
>
> On Tuesday, 3 February 2026 13:00:18 Pacific Standard Time Ell wrote:
>
> > OTOH producers of null-terminated strings don't know how the string is
> > going to be used, so it makes sense to return a string_view with the
> > added information that it's null terminated (as in
> > https://eel.is/c++draft/meta.reflection#meta.syn-3). This information is
> > useful even in the presence of embedded nulls (at the very least, it
> > allows you to safely strlen() the string). The name "cstring_view" might
> > be misleading though, if the actual C-string might be different.
>
>
> If I'm producing one, then "view" is the wrong type. It should be just
> std::string with a promise of not containing an embedded NUL.
>

Bad word choice on my part. My point was that cstring_view makes more
sense on the providing end than the receiving end. Some APIs provide
existing strings without transfer of ownership or a copy. Obviously, if
you return a new string then it's irrelevant.

Received on 2026-02-04 16:16:10