r/cpp • wx | soci | swig • Jun 17 '15

Standardizing Variant: Difficult Decisions

https://www.justsoftwaresolutions.co.uk/cplusplus/standardizing-variant.html
34 Upvotes

56 comments sorted by

View all comments

Show parent comment

3

u/Plorkyeran Jun 17 '15

Not writing throwing moves seems like a pretty good rule of thumb too. Are there any actual sane use-case for them?

3

u/eric_niebler Jun 17 '15

For rather obscure reasons having to do with sentinel nodes and iterator invalidation, the node-based containers (list, map, etc.) have potentially throwing move constructors.

3

u/sellibitze Jun 18 '15

IIRC one of the motivations to allow throwing move ctors was std::pair<some_legacy_type, some_move_optimized_type> where some_legacy_type only has a possibly throwing copy ctor and some_move_optimized_type comes with a non-throwing move ctor. So, you end up with a possibly throwing move ctor for this pair. But it will be preferable to its copy ctor in the situations where you don't need a move to have the strong exception guarantee.

But yeah, throwing move ctors are making things complicated. In other languages like D and Rust, the move semantics story is much simpler (and a teensy bit less powerful but that's IMHO ok).