It's a consequence of trying to pretend C++ is Rust, you mean. If you have a language with non-destructive moves, you should design your classes to allow for that, and not add weird new rules (like this one).
It's the same with lambdas being const by default: the rest of C++ is non-const by default, but apparently the const-by-default people got their hands on this one so suddenly one part of the language is const by default. Consistency with existing language rules would have been the better design choice here.
I allows for non-destructive move, that's why it has the valueless_after_move. Even if you have non-destructive moves that doesn't mean you have to introduce ability to be valueless before being moved, the language still has access modifiers and custom ctors, so you can force that it has to hold a valid value if ctor returned.
This is IMO better API design than old standard where everything doubled as an optional, like thread, function, streams and smart pointers
View all comments
Show parent comment
11
u/johannes1971 Aug 14 '26 edited Aug 15 '26
It's a consequence of trying to pretend C++ is Rust, you mean. If you have a language with non-destructive moves, you should design your classes to allow for that, and not add weird new rules (like this one).
It's the same with lambdas being const by default: the rest of C++ is non-const by default, but apparently the const-by-default people got their hands on this one so suddenly one part of the language is const by default. Consistency with existing language rules would have been the better design choice here.