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

Standardizing Variant: Difficult Decisions

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

56 comments sorted by

View all comments

Show parent comment

3

u/sbabbi Jun 17 '15

I actually implemented a variant for fun a while ago. I went with this solution, and still believe it is the only logical way to implement the assignment. Who the hell writes a type that is not nothrow_move_ constructible, seriously?

7

u/F-J-W Jun 17 '15

Everyone who forgets to annotate a non-implicit move-ctor.

1

u/[deleted] Jun 18 '15

Who the hell writes a type that is not nothrow_move_ constructible, seriously?

That's just what I thought but it seems this is very common :/

1

u/sellibitze Jun 18 '15

std::pair<legacy_type_with_throwing_copy_ctor, std::string> has a possibly throwing move ctor.

1

u/Shokwav Jun 19 '15

I've written one when I had to pass the address of an object to a legacy C function and couldn't modify it after initialization. But that's a rare case...