
On Thu, Sep 25, 2025 at 3:42 AM Andrzej Krzemienski via Boost < boost@lists.boost.org> wrote:
śr., 24 wrz 2025 o 21:26 Emil Dotchevski via Boost <boost@lists.boost.org> napisał(a):
Can a zero-terminated string view return the size?
The "zero-terminated string view", much like std::string_view, holds a pointer and a size, so it can return the size in constant time.
(It also has to maintain an invariant that the null-terminator mark is consistent with the separately stored size.)
Just a minor comment regarding my use-case: When passing the string on to a C-API, calculating the size is unnecessary & would introduce overhead. For example: void foo(cstring_view value) { c_foo(value.c_str()); } foo("very long string"); Would calculate the strlen for no reason. That doesn't mean the cstring_view shouldn't calculate the size, I am just saying that my cstring_ref written specifically for this one use-case doesn't keep a size on purpose.