Closed oktonion closed 5 years ago
According to the C++ standard (§9.5.1):
A union can have member functions (including constructors and destructors), but not virtual functions. A union shall not have base classes. A union shall not be used as a base class. An object of a class with a non-trivial constructor, a non-trivial copy-constructor, a non-trivial destructor, or a non-trivial copy assignment operator cannot be a member of a union, nor can an array of such objects. If a union contains a static data member, or a member of a reference type, the program is ill-formed.
So nothing can be done except using compiler intrinsic support.
Currently is_union has a bug of detecting class as union. This leads to is_class detecting union as class. And that circle of bugs is awful. Have no idea how to distinguish union from class at compile-time without compile-time errors. Boost is not good at this either - all they do is to use compiler specific build-in macro when possible.