Brian Silverman | 4a2409e | 2018-08-04 23:24:02 -0700 | [diff] [blame^] | 1 | [/ |
| 2 | Copyright 2007 John Maddock. |
| 3 | Distributed under the Boost Software License, Version 1.0. |
| 4 | (See accompanying file LICENSE_1_0.txt or copy at |
| 5 | http://www.boost.org/LICENSE_1_0.txt). |
| 6 | ] |
| 7 | |
| 8 | [section:is_union is_union] |
| 9 | template <class T> |
| 10 | struct is_union : public __tof {}; |
| 11 | |
| 12 | __inherit If T is a (possibly cv-qualified) union type then inherits from __true_type, |
| 13 | otherwise inherits from __false_type. Currently requires some kind of compiler |
| 14 | support, otherwise unions are identified as classes. |
| 15 | |
| 16 | __std_ref 3.9.2 and 9.5. |
| 17 | |
| 18 | __compat Without (some as yet unspecified) help from the |
| 19 | compiler, we cannot distinguish between union and class types using only standard C++, |
| 20 | as a result this type will never inherit from __true_type, unless the user explicitly |
| 21 | specializes the template for their user-defined union types, or unless the compiler |
| 22 | supplies some unspecified intrinsic that implements this functionality. |
| 23 | Currently (June 2015) compilers more recent than Visual C++ 8, clang, GCC-4.3, Greenhills 6.0, |
| 24 | Intel-11.0, and Codegear have the necessary compiler __intrinsics to ensure that this |
| 25 | trait "just works". You may also test to see if the necessary __intrinsics are available |
| 26 | by checking to see if the macro `BOOST_IS_UNION` is defined. |
| 27 | |
| 28 | |
| 29 | __header ` #include <boost/type_traits/is_union.hpp>` or ` #include <boost/type_traits.hpp>` |
| 30 | |
| 31 | __examples |
| 32 | |
| 33 | Given `union my_union {};` then: |
| 34 | |
| 35 | [:`is_union<my_union>` inherits from `__true_type`.] |
| 36 | |
| 37 | [:`is_union<const my_union>::type` is the type `__true_type`.] |
| 38 | |
| 39 | [:`is_union<my_union>::value` is an integral constant |
| 40 | expression that evaluates to /true/.] |
| 41 | |
| 42 | [:`is_union<my_union*>::value` is an integral constant |
| 43 | expression that evaluates to /false/.] |
| 44 | |
| 45 | [:`is_union<T>::value_type` is the type `bool`.] |
| 46 | |
| 47 | [endsect] |
| 48 | |