3 ms·
optional<non_null_unique_ptr<T>> would be completely feasible in C++. It is just that std::optional and unique_ptr do not have the right semantics out of the b
by gpderetta 3y ago
optional<non_null_unique_ptr<T>> would be completely feasible in C++.
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....
- CodesInChaos 3y agoThe problem with adding a non_null_unique_ptr<T> to C++ is that moving needs to leave behind a valid value.
- gpderetta 3y agoYou 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.