Re:Why Rust helps even if you have to use a lot of `unsafe`
by CodesInChaos on Wednesday August 02, 2023 @12:29PM
(#36973149)
The problem with adding a non_null_unique_ptr<T> to C++ is that moving needs to leave behind a valid value.
Re:Why Rust helps even if you have to use a lot of `unsafe`
by gpderetta on Wednesday August 02, 2023 @01:02PM
(#36973607)
You are right, but you could make it not movable (and add destructive mode hooks for optional and containers).
It is still possible to return non-movable, non-copyable types from functions.
But I guess ergonomics would not be good.
It is just that std::optional and unique_ptr do not have the right semantics out of the box, but it is not hard to roll your own.
But yes, I wish C++ has good builtin sum types and proper destructuring via pattern patching. Maybe one day....