Re:C++ Coroutines Do Not Spark Joy
by another2another on Friday April 05, 2024 @09:39AM
(#39942232)
To really make string_view sane and safe, you'd have to make std::string reference counted (with each string view holding a ref), but I can't see that being popular.
Re:C++ Coroutines Do Not Spark Joy
by sirwhinesalot on Friday April 05, 2024 @11:26AM
(#39943576)
string_view (like span) is meant for spatial memory safety, C++ doesn't help much with temporal memory safety.
That said, span (unlike string_view) fails at its intended purpose, because C++ just loves to be a total clown show.
> Enforcing safety seems like the right call
It certainly is, however it is hard to argue this point while looking at other more or less recent features:
string_view is basically a fancy "char *", with all the same use-after-free issues (same with other pointer range types and iterators)
Lambas with capture-by-reference can be freely copied and type erased into function<>, so obviously they did not care about safety when that feature got included