r/cpp • u/_VZ_ wx | soci | swig • Jun 17 '15
Standardizing Variant: Difficult Decisions
https://www.justsoftwaresolutions.co.uk/cplusplus/standardizing-variant.html
31
Upvotes
r/cpp • u/_VZ_ wx | soci | swig • Jun 17 '15
View all comments
Show parent comment
2
u/[deleted] Jun 18 '15 edited Jun 18 '15
For move assignment,
A = std::move(B)... to preserve iterators you would need to moveB's sentinel over toAandBwould need to allocate a new sentinel to represent its newend. That allocation could potentially throw, and hence move assignment can not benoexcept.I read the ISO C++ mailing list and remember reading about various ways to solve this problem, and it's unbelievably ugly, not to plug Rust or anything, but they got this right. In Rust, move operations never throw, for any object, period. Moves in Rust just work as you would expect them to and I think C++ could potentially learn from that language by making move semantics destroy the original object, as in make the object unusable after a move operation.
If the object becomes unusable after a move... this problem goes away, along with a host of other issues.