is_union.qbk 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. [section:is_union is_union]
  8. template <class T>
  9. struct is_union : public __tof {};
  10. __inherit If T is a (possibly cv-qualified) union type then inherits from __true_type,
  11. otherwise inherits from __false_type. Currently requires some kind of compiler
  12. support, otherwise unions are identified as classes.
  13. __std_ref 3.9.2 and 9.5.
  14. __compat Without (some as yet unspecified) help from the
  15. compiler, we cannot distinguish between union and class types using only standard C++,
  16. as a result this type will never inherit from __true_type, unless the user explicitly
  17. specializes the template for their user-defined union types, or unless the compiler
  18. supplies some unspecified intrinsic that implements this functionality.
  19. Currently (June 2015) compilers more recent than Visual C++ 8, clang, GCC-4.3, Greenhills 6.0,
  20. Intel-11.0, and Codegear have the necessary compiler __intrinsics to ensure that this
  21. trait "just works". You may also test to see if the necessary __intrinsics are available
  22. by checking to see if the macro `BOOST_IS_UNION` is defined.
  23. __header ` #include <boost/type_traits/is_union.hpp>` or ` #include <boost/type_traits.hpp>`
  24. __examples
  25. Given `union my_union {};` then:
  26. [:`is_union<my_union>` inherits from `__true_type`.]
  27. [:`is_union<const my_union>::type` is the type `__true_type`.]
  28. [:`is_union<my_union>::value` is an integral constant
  29. expression that evaluates to /true/.]
  30. [:`is_union<my_union*>::value` is an integral constant
  31. expression that evaluates to /false/.]
  32. [:`is_union<T>::value_type` is the type `bool`.]
  33. [endsect]