2 // (C) Copyright Dave Abrahams, Steve Cleary, Beman Dawes, Howard
3 // Hinnant & John Maddock 2000. Permission to copy, use, modify,
4 // sell and distribute this software is granted provided this
5 // copyright notice appears in all copies. This software is provided
6 // "as is" without express or implied warranty, and with no claim as
7 // to its suitability for any purpose.
9 // See http://www.boost.org 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/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/config.hpp"
20 #ifdef BOOST_TT_HAS_CONFORMING_IS_CLASS_IMPLEMENTATION
21 # include "boost/type_traits/is_class.hpp"
24 // should be the last #include
25 #include "boost/type_traits/detail/bool_trait_def.hpp"
29 #if !(defined(__BORLANDC__) && (__BORLANDC__ <= 0x551))
33 struct int_convertible
38 // Don't evaluate convertibility to int_convertible unless the type
39 // is non-arithmetic. This suppresses warnings with GCC.
40 template <bool is_typename_arithmetic_or_reference = true>
43 template <typename T> struct type
45 BOOST_STATIC_CONSTANT(bool, value = false);
50 struct is_enum_helper<false>
52 template <typename T> struct type
53 : ::boost::is_convertible<T,::boost::detail::int_convertible>
58 template <typename T> struct is_enum_impl
60 typedef ::boost::add_reference<T> ar_t;
61 typedef typename ar_t::type r_type;
63 #if defined(BOOST_TT_HAS_CONFORMING_IS_CLASS_IMPLEMENTATION)
64 BOOST_STATIC_CONSTANT(bool, selector =
65 (::boost::type_traits::ice_or<
66 ::boost::is_arithmetic<T>::value
67 , ::boost::is_reference<T>::value
68 // We MUST do this on conforming compilers in order to
69 // correctly deduce that noncopyable types are not enums (dwa
71 , ::boost::is_class<T>::value
74 BOOST_STATIC_CONSTANT(bool, selector =
75 (::boost::type_traits::ice_or<
76 ::boost::is_arithmetic<T>::value
77 , ::boost::is_reference<T>::value
78 // However, not doing this on non-conforming compilers prevents
79 // a dependency recursion.
84 typedef ::boost::detail::is_enum_helper<
85 ::boost::detail::is_enum_impl<T>::selector
88 typedef ::boost::detail::is_enum_helper<selector> se_t;
90 typedef typename se_t::template type<r_type> helper;
91 BOOST_STATIC_CONSTANT(bool, value = helper::value);
94 // Specializations suppress some nasty warnings with GCC
95 BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_enum,float,false)
96 BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_enum,double,false)
97 BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_enum,long double,false)
98 // these help on compilers with no partial specialization support:
99 BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_enum,void,false)
100 #ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS
101 BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_enum,void const,false)
102 BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_enum,void volatile,false)
103 BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_enum,void const volatile,false)
106 } // namespace detail
108 BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_enum,T,::boost::detail::is_enum_impl<T>::value)
110 #else // __BORLANDC__
112 // buggy is_convertible prevents working
113 // implementation of is_enum:
114 BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_enum,T,false)
120 #include "boost/type_traits/detail/bool_trait_undef.hpp"
122 #endif // BOOST_TT_IS_ENUM_HPP_INCLUDED