r/cpp • u/_VZ_ wx | soci | swig • Jun 17 '15
Standardizing Variant: Difficult Decisions
https://www.justsoftwaresolutions.co.uk/cplusplus/standardizing-variant.html
32
Upvotes
r/cpp • u/_VZ_ wx | soci | swig • Jun 17 '15
View all comments
Show parent comment
1
u/[deleted] Jun 17 '15 edited Jun 17 '15
I like your solution: move constructors are noexcept for most of std types and it is a general guideline that they should be noexcept for user defined types as well.
At the same time, I want variants to be default constructible, and thus they should have an empty state, but I don't like to have a tag type for that.
What does a default constructed variant mean?
Since a variant can have many values, but the user didn't care enough to pass any to me it means that is empty. All the arguments about default constructing the first type that is default constructible seem very complicated. At least if one access an empty variant one gets a loud exception. Getting a default constructed random value from the variant looks like more prone to cause silent bugs to me.