Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

Click here to view the latest version of this page.
PrevUpHomeNext

is_union

template <class T>
struct is_union : public true_type-or-false_type {};

Inherits: If T is a (possibly cv-qualified) union type then inherits from true_type, otherwise inherits from false_type. Currently requires some kind of compiler support, otherwise unions are identified as classes.

C++ Standard Reference: 3.9.2 and 9.5.

Compiler Compatibility: Without (some as yet unspecified) help from the compiler, we cannot distinguish between union and class types using only standard C++, as a result this type will never inherit from true_type, unless the user explicitly specializes the template for their user-defined union types, or unless the compiler supplies some unspecified intrinsic that implements this functionality. Currently (May 2011) compilers more recent than Visual C++ 8, GCC-4.3, Greenhills 6.0, Intel-11.0, and Codegear have the necessary compiler intrinsics to ensure that this trait "just works". You may also test to see if the necessary intrinsics are available by checking to see if the macro BOOST_IS_UNION is defined.

Header: #include <boost/type_traits/is_union.hpp> or #include <boost/type_traits.hpp>

Examples:

is_union<void> inherits from true_type.

is_union<const void>::type is the type true_type.

is_union<void>::value is an integral constant expression that evaluates to true.

is_union<void*>::value is an integral constant expression that evaluates to false.

is_union<T>::value_type is the type bool.


PrevUpHomeNext