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).
8 // See http://www.boost.org/libs/type_traits for most recent version including documentation.
11 #ifndef BOOST_TT_IS_ENUM_HPP_INCLUDED
12 #define BOOST_TT_IS_ENUM_HPP_INCLUDED
14 #include <boost/type_traits/intrinsics.hpp>
16 #include <boost/type_traits/add_reference.hpp>
17 #include <boost/type_traits/is_arithmetic.hpp>
18 #include <boost/type_traits/is_reference.hpp>
19 #include <boost/type_traits/is_convertible.hpp>
20 #include <boost/type_traits/is_array.hpp>
22 #include <boost/type_traits/is_function.hpp>
24 #include <boost/type_traits/config.hpp>
25 #if defined(BOOST_TT_HAS_CONFORMING_IS_CLASS_IMPLEMENTATION)
26 # include <boost/type_traits/is_class.hpp>
27 # include <boost/type_traits/is_union.hpp>
31 // should be the last #include
32 #include <boost/type_traits/detail/bool_trait_def.hpp>
37 #if !(defined(__BORLANDC__) && (__BORLANDC__ <= 0x551))
41 #if defined(BOOST_TT_HAS_CONFORMING_IS_CLASS_IMPLEMENTATION)
44 struct is_class_or_union
46 BOOST_STATIC_CONSTANT(bool, value =
47 (::boost::type_traits::ice_or<
48 ::boost::is_class<T>::value
49 , ::boost::is_union<T>::value
56 struct is_class_or_union
58 # if BOOST_WORKAROUND(BOOST_MSVC, < 1300) || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x581))// we simply can't detect it this way.
59 BOOST_STATIC_CONSTANT(bool, value = false);
61 template <class U> static ::boost::type_traits::yes_type is_class_or_union_tester(void(U::*)(void));
63 # if BOOST_WORKAROUND(BOOST_MSVC, == 1300) \
64 || BOOST_WORKAROUND(__MWERKS__, <= 0x3000) // no SFINAE
65 static ::boost::type_traits::no_type is_class_or_union_tester(...);
66 BOOST_STATIC_CONSTANT(
67 bool, value = sizeof(is_class_or_union_tester(0)) == sizeof(::boost::type_traits::yes_type));
70 static ::boost::type_traits::no_type is_class_or_union_tester(...);
71 BOOST_STATIC_CONSTANT(
72 bool, value = sizeof(is_class_or_union_tester<T>(0)) == sizeof(::boost::type_traits::yes_type));
78 struct int_convertible
83 // Don't evaluate convertibility to int_convertible unless the type
84 // is non-arithmetic. This suppresses warnings with GCC.
85 template <bool is_typename_arithmetic_or_reference = true>
88 template <typename T> struct type
90 BOOST_STATIC_CONSTANT(bool, value = false);
95 struct is_enum_helper<false>
97 template <typename T> struct type
98 : ::boost::is_convertible<typename boost::add_reference<T>::type,::boost::detail::int_convertible>
103 template <typename T> struct is_enum_impl
105 //typedef ::boost::add_reference<T> ar_t;
106 //typedef typename ar_t::type r_type;
108 #if defined(__GNUC__)
110 #ifdef BOOST_TT_HAS_CONFORMING_IS_CLASS_IMPLEMENTATION
112 // We MUST check for is_class_or_union on conforming compilers in
113 // order to correctly deduce that noncopyable types are not enums
114 // (dwa 2002/04/15)...
115 BOOST_STATIC_CONSTANT(bool, selector =
116 (::boost::type_traits::ice_or<
117 ::boost::is_arithmetic<T>::value
118 , ::boost::is_reference<T>::value
119 , ::boost::is_function<T>::value
120 , is_class_or_union<T>::value
124 // ...however, not checking is_class_or_union on non-conforming
125 // compilers prevents a dependency recursion.
126 BOOST_STATIC_CONSTANT(bool, selector =
127 (::boost::type_traits::ice_or<
128 ::boost::is_arithmetic<T>::value
129 , ::boost::is_reference<T>::value
130 , ::boost::is_function<T>::value
133 #endif // BOOST_TT_HAS_CONFORMING_IS_CLASS_IMPLEMENTATION
135 #else // !defined(__GNUC__):
137 BOOST_STATIC_CONSTANT(bool, selector =
138 (::boost::type_traits::ice_or<
139 ::boost::is_arithmetic<T>::value
140 , ::boost::is_reference<T>::value
141 , is_class_or_union<T>::value
147 #if BOOST_WORKAROUND(__BORLANDC__, < 0x600)
148 typedef ::boost::detail::is_enum_helper<
149 ::boost::detail::is_enum_impl<T>::selector
152 typedef ::boost::detail::is_enum_helper<selector> se_t;
155 typedef typename se_t::template type<T> helper;
156 BOOST_STATIC_CONSTANT(bool, value = helper::value);
159 // these help on compilers with no partial specialization support:
160 BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_enum,void,false)
161 #ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS
162 BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_enum,void const,false)
163 BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_enum,void volatile,false)
164 BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_enum,void const volatile,false)
167 } // namespace detail
169 BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_enum,T,::boost::detail::is_enum_impl<T>::value)
171 #else // __BORLANDC__
173 // buggy is_convertible prevents working
174 // implementation of is_enum:
175 BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_enum,T,false)
179 #else // BOOST_IS_ENUM
181 BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_enum,T,BOOST_IS_ENUM(T))
187 #include <boost/type_traits/detail/bool_trait_undef.hpp>
189 #endif // BOOST_TT_IS_ENUM_HPP_INCLUDED