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
1
u/johannes1971 May 13 '26
The point is that you can never safely construct a cstring_view from a string_view, you have to know in advance that the null terminator is there and with string_view you just don't know. With string and string literals you do know, so then it's safe. The number of places where I use a string_view without a zero terminator is much smaller than the number of places where I have to construct a string just to guarantee that zero terminator, so cstring_view would be a welcome improvement.
I disagree that eliminating a mandatory memory allocation for something that could easily be handled by something like cstring_view is over engineering.