3 ms·
The new move semantics use null references for things moved from. No. When you move the contents out of somewhere like an std::vector instance, that object is
by nhaehnle 11y ago
The new move semantics use null references for things moved from.
No. When you move the contents out of somewhere like an std::vector instance, that object is left in an undefined but valid state. You're free to continue working with that object (though the only meaningful thing you can usually do without undefined behaviour is destruction or the equivalent of clear). That's very different from null references.
- Animats 11y agoRight; you can't have an array of references, and it's "unique_ptr", not "unique_ref". But pointers do get set to null. If p1 is a unique_ptr, and you do p2 = std::move(p1); p1's pointer is set to null. Further uses of p1 will fail, or crash, or something. p1.get() returns the underlying pointer or null, apparently escaping the unique_ptr protection. It's far inferior to Rust's borrow checker.