I solved this problem by creating an alternative string_view
class called zstring_view
. It is privately inherited from string_view
and contains most of its interface.
The fundamental difference is that zstring_view
cannot be created from string_view
. In addition, any string_view
that remove elements from the end are not part of the interface or return string_view
instead of zstring_view
.
They can be created from any NUL-terminal string source: std::string
and so on. I even created special custom letter suffixes for them: _zsv
.
The idea is that until you manually place a line without zstring_view
in zstring_view
, all zstring_view
must be NUL-terminated. Like std::string
, the NUL character is not part of the size of the string, but it is.
I believe that this is very useful for interacting with the C interface.
source share