On Tue, 2022-05-10 at 21:15 -0700, Marshall Clow via Boost wrote:
On May 10, 2022, at 8:35 PM, Klemens Morgenstern via Boost
wrote: Hi y'all,
I've hacked together a cstring_view class and would like to ask if it could be included in boost.utility or boost.core.
https://gist.github.com/klemens-morgenstern/fc02dab8b37fc77ac80efbca30f297cf
The main motivation is to have a view that works with C-APIs. I also need the char_traits for dealing with odd char semantics for some system APIs. (e.g. environment keys on windows are char-insensitive but preserving).
I don’t see how this is supposed to maintain the invariant ( null temination) w/o it’s own storage.
There's a static "" for default initialization. BOOST_CONSTEXPR static const_pointer null_char_() {return null_char_(CharT{});} BOOST_CONSTEXPR static const char* null_char_(char) {return "";} BOOST_CONSTEXPR static const wchar_t* null_char_(wchar_t) {return L"";}
Consider: cstring_view sv; // is sv-data() pointing to a null-terminated string? If so, where did it come from?
cstring_view sv1(“abcdefg”)’ sv1.substring(3, 2); // what’s the value of strlen(sv.data) here? How can it be 2?
The substr returns a string_view if you pass it a second parameter: BOOST_CONSTEXPR basic_cstring_view substr(size_type pos = 0) const; BOOST_CONSTEXPR string_view_type substr(size_type pos , size_type n) const; I can only move the starting character with substr and maintain the null-terminator, so if I change the end, I'll get a regular string_view.
— Marshall
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost