r/cpp • u/pavel_v • Apr 30 '26
C++26: string and string_view improvements
https://www.sandordargo.com/blog/2026/04/29/cpp26-string-string_view-improvements
70
Upvotes
r/cpp • u/pavel_v • Apr 30 '26
View all comments
Show parent comment
2
u/Zeh_Matt No, no, no, no May 12 '26
Well as they say, nothing is ever really free, there are couple issues still that would need to be addressed, what if the string buffer mutates it after the cstring_view is constructed, it might remove the null terminator, yes string_views could also have mutating buffers but the guarantee here is that its bounded by size and not a sentinel. Also how do you actually handle the case when your string lacks the null terminator, throw? return an empty object? I honestly don't think its worth a new type, if you want to add some safety you could have a function like get_cstring_view() that checks if the input has a null terminator and otherwise throw or however you want to handle this situation, you could even alias string_view to make the distinction a little bit better. I'm quite confident due to the reasons I stated above this will never really land in the standard, and in C++ we shouldn't be really dealing with null terminated strings anyway, this is usually just needed when dealing with C apis.