4 ms·
One tough thing about rule of zero classes is that many to most end up having an implicit 'the object has not been moved from' precondition on methods. The clas
by partiallattice 6y ago
One tough thing about rule of zero classes is that many to most end up having an implicit 'the object has not been moved from' precondition on methods. The classic example is a class with a unique_ptr member that is never null except after move, so none of the methods have null checks.
I understand why the committee was unable to get destructive moves into the standard, but I do think that is one thing Rust got right that I really wish C++ had.
- MaxBarraclough 6y agoAgree. Can't really blame C++ for it being difficult to retrofit something like that. It's akin to the lack of const in Java: they'd add it if it were practical to do so.
- tragomaskhalos 6y agoPeople bang on about borrow checking etc but really it's move semantics that's the million dollar idea in Rust - it just obliterates a huge Gordian knot of complexity in one stroke
- ncmncm 6y agoIn Rust you cannot write a move constructor. That proves limiting. But Rust move construction, also, cannot fail, which is liberating. Rust cannot abandon backward compatibility with itself, so will increasingly be stuck with old choices, like C++, and will soon be fully as complex and infuriating. But it will, like C++, remain usually more useful than alternatives.