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
11
u/F-J-W Jun 17 '15
Either it should never be empty, or empty should be a relatively normal thing. It being a very rare thing just creates bugs because people will ignore it.
Regarding the solutions: One is missing: require noexcept move-ctor and do a three step assignment:
tby copying the new value (may throw)t. (noexcept per requirement)That aside: I believe that a default-ctor that creates an instance of one of the many arguments is a bad-idea. Make that ill-formed and maybe offer to pass in an instance of std::integral_constant<std::size_t, N> that tells the ctor to default-construct the N'th value.
Regarding a tag-type to allow empty states if they are not always allowed, I believe that we already have that “type” in the core-language:
voidI think it is obvious what it would mean and it represents a clean solution.