r/cpp • u/_VZ_ wx | soci | swig • Jun 17 '15
Standardizing Variant: Difficult Decisions
https://www.justsoftwaresolutions.co.uk/cplusplus/standardizing-variant.html
31
Upvotes
r/cpp • u/_VZ_ wx | soci | swig • Jun 17 '15
View all comments
Show parent comment
2
u/cdglove Jun 19 '15
Variant is a value type. Value types should never have a valid empty state. What you're saying applies to reference types and is more akin to Java style null checks. I really don't want that. If you do, however, you can implement it yourself in terms of the current variant by making your own 'none' type. The same is not true for the reverse; if variant is default constructed as empty I am forced to check everywhere because empty has been promoted to a valid state. In my opinion it's generally bad design to force users to use a library is a certain way like this.