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

Standardizing Variant: Difficult Decisions

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

56 comments sorted by

View all comments

Show parent comment

1

u/suspiciously_calm Jun 18 '15

Do you feel the same about built-in unions?

Yes.

I'm sure you would agree that swallowing exceptions and continuing as if nothing went wrong is a bad thing. Should we compromise the design of our vocabulary types -- complicating their use everywhere and for everyone -- to accommodate bad code?

It doesn't complicate use, since a variant holding the wrong type is also a real possibility, and it doesn't complicate the design of the type either, since the "invalid state" representation has to be there anyway. The only difference is whether the default constructor constructs an empty variant or one of the variant types which is selected by some arbitrary rule.