C++ Logo


Advanced search

Re: [SG16-Unicode] SG16 approval for LEWG to review std::filesystem::path_view

From: JeanHeyd Meneide <phdofthehouse_at_[hidden]>
Date: Wed, 3 Jul 2019 16:14:16 -0400
Dear Lyberta,

On Wed, Jul 3, 2019 at 3:40 PM Lyberta <lyberta_at_[hidden]> wrote:

> Since std::c_string_view would not own the string, how do you enforce
> the null terminator because the user can mutate the buffer. Do you check
> manually in every member function and assert?

      The plan would be with an assert() on construction, at the very
least, or a contract check on both the constructor and the .c_str()
methods. That would seem like a reasonable compromise. Even if it's not
strictly enforceable, it's infinitely better than `const CharT*` + size
because it tells the user -- semantically -- what is expected, without
having to read the specification / standard.

      Really, my only qualm with demanding const CharT* and
basic_string_view<X>'s be null terminated is that there's no way to know.
Some APIs require it, some don't, and there's no way to tell without
carefully thumbing through the docs. It's not a good user experience: even
if c_string_view did nothing but privately derive from string_view and
forward all methods, that'd still be an immense improvement because at
least somewhere it's documented.


Received on 2019-07-03 22:14:28