You can't in the general case because you have to call the constructor of the appropriate internal type. You can't placement new, so you have to do it via a member initializer, so which internal type's constructor do you call?
I see. You have to decide the member initialization based on a runtime
value.
Thats just not possible.
However, the more I think about it, I don't think a constexpr union type
makes
much sense. The type is known at compile-time. Instead a constexpr sum type
would just store the type and the possible types:
template