These are chat archives for boostorg/hana
So if you write this:
constexpr variant<int, char> v = 'C'; constexpr int i = get<0>(v); constexpr int j = get<int>(v);
It will give a compile-error at compile time; but it will throw an exception at runtime.
constexprvariant is a nice utility, but I don’t think it makes much sense for Hana. Here’s why: If a variant was to be included in Hana, it would have to know what type it contains (out of the N possible variants) at compile-time, just like
hana::optionalknows whether it is empty or not at compile-time. And by compile-time, I really mean that the information is encoded in the type of the variant, not only that the variant can be used inside a constant expression.
hana::eitherat some point (which is really just a binary
variant), but it was removed precisely for this reason.
constexprvariant, but I don’t quite understand the implementation (it seems to be based on tuple, not union, which is strange).
boost::variantaims to be a more general purpose variant from what I understand, and I don’t know whether it’s possible to make its implementation
constexpr. Are there significant differences between your variant and e.g.
variant<int, char> v = 42; variant<int, char, double> v2 = v;