
Hey, A type like this is extremely important, especially because `string_view` easily becomes a footgun when one doesn't realise that `data()` is not guaranteed to be null-terminated, or that the size itself is not pointing to the actual null-terminator. Additionally, a cstring view type helps with unnecessary conversions to string with the intent to guarantee that a string is null-terminated. There's also a lot to be said that using raw `const char*` is a source of problems, so you want to treat null-terminated strings as a contiguous range, similar to span, and where there are no surprises about the length, but at the same time with all the goodies that come with a string-specific type. Chromium actually offers a type like this, and there are even extensions to Chromium's span type to handle conversion to byte span that should or should not include the null-terminator. For reference, link below: https://source.chromium.org/chromium/chromium/src/+/main:base/strings/cstrin... Claudio. On Wed, Sep 24, 2025 at 8:21 PM Andrzej Krzemienski via Boost < boost@lists.boost.org> wrote:
Hi Everyone, Would Boost libraries benefit from having a string_view-like type with the guarantee that the underlying character sequence is null-terminated?
This could be as yet another Boost library, or as part of Boost.Core. Maybe Boost already has such a type somewhere?
The need for such a type surfaces time and again. When a library needs to be passed both const char * and std::string cheaply, only to pass it down to low-level C-libraries later. We have seen one recently during the review of Boost.Sqlite. One is again proposed for standardization: wg21.link/p3655.
Regards, &rzej; _______________________________________________ Boost mailing list -- boost@lists.boost.org To unsubscribe send an email to boost-leave@lists.boost.org https://lists.boost.org/mailman3/lists/boost.lists.boost.org/ Archived at: https://lists.boost.org/archives/list/boost@lists.boost.org/message/E3D7ZHSI...