[857] | 1 |
|
---|
| 2 | // (C) Copyright Dave Abrahams, Steve Cleary, Beman Dawes, Howard
|
---|
| 3 | // Hinnant & John Maddock 2000.
|
---|
| 4 | // Use, modification and distribution are subject to the Boost Software License,
|
---|
| 5 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
---|
| 6 | // http://www.boost.org/LICENSE_1_0.txt).
|
---|
| 7 | //
|
---|
| 8 | // See http://www.boost.org/libs/type_traits for most recent version including documentation.
|
---|
| 9 |
|
---|
| 10 |
|
---|
| 11 | #ifndef BOOST_TT_IS_ENUM_HPP_INCLUDED
|
---|
| 12 | #define BOOST_TT_IS_ENUM_HPP_INCLUDED
|
---|
| 13 |
|
---|
| 14 | #include "boost/type_traits/add_reference.hpp"
|
---|
| 15 | #include "boost/type_traits/is_arithmetic.hpp"
|
---|
| 16 | #include "boost/type_traits/is_reference.hpp"
|
---|
| 17 | #include "boost/type_traits/is_convertible.hpp"
|
---|
| 18 | #include "boost/type_traits/is_array.hpp"
|
---|
| 19 | #ifdef __GNUC__
|
---|
| 20 | #include <boost/type_traits/is_function.hpp>
|
---|
| 21 | #endif
|
---|
| 22 | #include "boost/type_traits/config.hpp"
|
---|
| 23 | #if defined(BOOST_TT_HAS_CONFORMING_IS_CLASS_IMPLEMENTATION)
|
---|
| 24 | # include <boost/type_traits/is_class.hpp>
|
---|
| 25 | # include <boost/type_traits/is_union.hpp>
|
---|
| 26 | #endif
|
---|
| 27 |
|
---|
| 28 |
|
---|
| 29 | // should be the last #include
|
---|
| 30 | #include "boost/type_traits/detail/bool_trait_def.hpp"
|
---|
| 31 |
|
---|
| 32 | namespace boost {
|
---|
| 33 |
|
---|
| 34 | #if !(defined(__BORLANDC__) && (__BORLANDC__ <= 0x551))
|
---|
| 35 |
|
---|
| 36 | namespace detail {
|
---|
| 37 |
|
---|
| 38 | #if defined(BOOST_TT_HAS_CONFORMING_IS_CLASS_IMPLEMENTATION)
|
---|
| 39 |
|
---|
| 40 | template <typename T>
|
---|
| 41 | struct is_class_or_union
|
---|
| 42 | {
|
---|
| 43 | BOOST_STATIC_CONSTANT(bool, value =
|
---|
| 44 | (::boost::type_traits::ice_or<
|
---|
| 45 | ::boost::is_class<T>::value
|
---|
| 46 | , ::boost::is_union<T>::value
|
---|
| 47 | >::value));
|
---|
| 48 | };
|
---|
| 49 |
|
---|
| 50 | #else
|
---|
| 51 |
|
---|
| 52 | template <typename T>
|
---|
| 53 | struct is_class_or_union
|
---|
| 54 | {
|
---|
| 55 | # if BOOST_WORKAROUND(BOOST_MSVC, == 1200) || BOOST_WORKAROUND(__BORLANDC__, <= 0x570)// we simply can't detect it this way.
|
---|
| 56 | BOOST_STATIC_CONSTANT(bool, value = false);
|
---|
| 57 | # else
|
---|
| 58 | template <class U> static ::boost::type_traits::yes_type is_class_or_union_tester(void(U::*)(void));
|
---|
| 59 |
|
---|
| 60 | # if BOOST_WORKAROUND(BOOST_MSVC, == 1300) \
|
---|
| 61 | || BOOST_WORKAROUND(__MWERKS__, <= 0x3000) // no SFINAE
|
---|
| 62 | static ::boost::type_traits::no_type is_class_or_union_tester(...);
|
---|
| 63 | BOOST_STATIC_CONSTANT(
|
---|
| 64 | bool, value = sizeof(is_class_or_union_tester(0)) == sizeof(::boost::type_traits::yes_type));
|
---|
| 65 | # else
|
---|
| 66 | template <class U>
|
---|
| 67 | static ::boost::type_traits::no_type is_class_or_union_tester(...);
|
---|
| 68 | BOOST_STATIC_CONSTANT(
|
---|
| 69 | bool, value = sizeof(is_class_or_union_tester<T>(0)) == sizeof(::boost::type_traits::yes_type));
|
---|
| 70 | # endif
|
---|
| 71 | # endif
|
---|
| 72 | };
|
---|
| 73 | #endif
|
---|
| 74 |
|
---|
| 75 | struct int_convertible
|
---|
| 76 | {
|
---|
| 77 | int_convertible(int);
|
---|
| 78 | };
|
---|
| 79 |
|
---|
| 80 | // Don't evaluate convertibility to int_convertible unless the type
|
---|
| 81 | // is non-arithmetic. This suppresses warnings with GCC.
|
---|
| 82 | template <bool is_typename_arithmetic_or_reference = true>
|
---|
| 83 | struct is_enum_helper
|
---|
| 84 | {
|
---|
| 85 | template <typename T> struct type
|
---|
| 86 | {
|
---|
| 87 | BOOST_STATIC_CONSTANT(bool, value = false);
|
---|
| 88 | };
|
---|
| 89 | };
|
---|
| 90 |
|
---|
| 91 | template <>
|
---|
| 92 | struct is_enum_helper<false>
|
---|
| 93 | {
|
---|
| 94 | template <typename T> struct type
|
---|
| 95 | : ::boost::is_convertible<typename boost::add_reference<T>::type,::boost::detail::int_convertible>
|
---|
| 96 | {
|
---|
| 97 | };
|
---|
| 98 | };
|
---|
| 99 |
|
---|
| 100 | template <typename T> struct is_enum_impl
|
---|
| 101 | {
|
---|
| 102 | //typedef ::boost::add_reference<T> ar_t;
|
---|
| 103 | //typedef typename ar_t::type r_type;
|
---|
| 104 |
|
---|
| 105 | #if defined(__GNUC__)
|
---|
| 106 |
|
---|
| 107 | #ifdef BOOST_TT_HAS_CONFORMING_IS_CLASS_IMPLEMENTATION
|
---|
| 108 |
|
---|
| 109 | // We MUST check for is_class_or_union on conforming compilers in
|
---|
| 110 | // order to correctly deduce that noncopyable types are not enums
|
---|
| 111 | // (dwa 2002/04/15)...
|
---|
| 112 | BOOST_STATIC_CONSTANT(bool, selector =
|
---|
| 113 | (::boost::type_traits::ice_or<
|
---|
| 114 | ::boost::is_arithmetic<T>::value
|
---|
| 115 | , ::boost::is_reference<T>::value
|
---|
| 116 | , ::boost::is_function<T>::value
|
---|
| 117 | , is_class_or_union<T>::value
|
---|
| 118 | , is_array<T>::value
|
---|
| 119 | >::value));
|
---|
| 120 | #else
|
---|
| 121 | // ...however, not checking is_class_or_union on non-conforming
|
---|
| 122 | // compilers prevents a dependency recursion.
|
---|
| 123 | BOOST_STATIC_CONSTANT(bool, selector =
|
---|
| 124 | (::boost::type_traits::ice_or<
|
---|
| 125 | ::boost::is_arithmetic<T>::value
|
---|
| 126 | , ::boost::is_reference<T>::value
|
---|
| 127 | , ::boost::is_function<T>::value
|
---|
| 128 | , is_array<T>::value
|
---|
| 129 | >::value));
|
---|
| 130 | #endif // BOOST_TT_HAS_CONFORMING_IS_CLASS_IMPLEMENTATION
|
---|
| 131 |
|
---|
| 132 | #else // !defined(__GNUC__):
|
---|
| 133 |
|
---|
| 134 | BOOST_STATIC_CONSTANT(bool, selector =
|
---|
| 135 | (::boost::type_traits::ice_or<
|
---|
| 136 | ::boost::is_arithmetic<T>::value
|
---|
| 137 | , ::boost::is_reference<T>::value
|
---|
| 138 | , is_class_or_union<T>::value
|
---|
| 139 | , is_array<T>::value
|
---|
| 140 | >::value));
|
---|
| 141 |
|
---|
| 142 | #endif
|
---|
| 143 |
|
---|
| 144 | #if BOOST_WORKAROUND(__BORLANDC__, < 0x600)
|
---|
| 145 | typedef ::boost::detail::is_enum_helper<
|
---|
| 146 | ::boost::detail::is_enum_impl<T>::selector
|
---|
| 147 | > se_t;
|
---|
| 148 | #else
|
---|
| 149 | typedef ::boost::detail::is_enum_helper<selector> se_t;
|
---|
| 150 | #endif
|
---|
| 151 |
|
---|
| 152 | typedef typename se_t::template type<T> helper;
|
---|
| 153 | BOOST_STATIC_CONSTANT(bool, value = helper::value);
|
---|
| 154 | };
|
---|
| 155 |
|
---|
| 156 | // these help on compilers with no partial specialization support:
|
---|
| 157 | BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_enum,void,false)
|
---|
| 158 | #ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS
|
---|
| 159 | BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_enum,void const,false)
|
---|
| 160 | BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_enum,void volatile,false)
|
---|
| 161 | BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_enum,void const volatile,false)
|
---|
| 162 | #endif
|
---|
| 163 |
|
---|
| 164 | } // namespace detail
|
---|
| 165 |
|
---|
| 166 | BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_enum,T,::boost::detail::is_enum_impl<T>::value)
|
---|
| 167 |
|
---|
| 168 | #else // __BORLANDC__
|
---|
| 169 | //
|
---|
| 170 | // buggy is_convertible prevents working
|
---|
| 171 | // implementation of is_enum:
|
---|
| 172 | BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_enum,T,false)
|
---|
| 173 |
|
---|
| 174 | #endif
|
---|
| 175 |
|
---|
| 176 | } // namespace boost
|
---|
| 177 |
|
---|
| 178 | #include "boost/type_traits/detail/bool_trait_undef.hpp"
|
---|
| 179 |
|
---|
| 180 | #endif // BOOST_TT_IS_ENUM_HPP_INCLUDED
|
---|