
czw., 25 wrz 2025 o 03:17 Klemens Morgenstern via Boost < boost@lists.boost.org> napisał(a):
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.
This is a very important observation. One "optimal" implementation of a null-terminated string_view may not be achievable. People will have various incompatible expectations, like: minimum compile-times, minimum dependencies versus, full string compatibility, including .at(), which drags std::runtime_error, which std::string, which drags memory allocation. Another would be, whether you get std::format support by default. 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/QGB3TK2Z...