r/cpp • u/_VZ_ wx | soci | swig • Jun 17 '15
Standardizing Variant: Difficult Decisions
https://www.justsoftwaresolutions.co.uk/cplusplus/standardizing-variant.html
34
Upvotes
r/cpp • u/_VZ_ wx | soci | swig • Jun 17 '15
View all comments
Show parent comment
3
u/foonathan Jun 18 '15
To actually do something, you need to switch on the type as well. So this argument is invalid, because you already need to have a conditional to check whether the variant has a certain type. And there is absolutely no difference between checking for a certain type or checking for any type. But this type checking is already solved with visitors for variants. They avoid the conditionals and in case of an empty variant, it can simply do nothing. An empty state does not lead to more conditionals than already present.
Otherwise, I completely agree with /u/F-J-W: either you allow an empty state or you don't, i.e. by requiring nothrow move. An invalid state makes it worse.