blob: 814632d716c3a44303a800edc99c05ebc7a7337c [file] [log] [blame]
Jeff Thompsonf7d49942013-08-01 16:47:40 -07001
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
Jeff Thompson2277ce52013-08-01 17:34:11 -070014#include <ndnboost/type_traits/intrinsics.hpp>
Jeff Thompsonf7d49942013-08-01 16:47:40 -070015#ifndef BOOST_IS_ENUM
Jeff Thompson2277ce52013-08-01 17:34:11 -070016#include <ndnboost/type_traits/add_reference.hpp>
17#include <ndnboost/type_traits/is_arithmetic.hpp>
18#include <ndnboost/type_traits/is_reference.hpp>
19#include <ndnboost/type_traits/is_convertible.hpp>
20#include <ndnboost/type_traits/is_array.hpp>
Jeff Thompsonf7d49942013-08-01 16:47:40 -070021#ifdef __GNUC__
Jeff Thompson2277ce52013-08-01 17:34:11 -070022#include <ndnboost/type_traits/is_function.hpp>
Jeff Thompsonf7d49942013-08-01 16:47:40 -070023#endif
Jeff Thompson2277ce52013-08-01 17:34:11 -070024#include <ndnboost/type_traits/config.hpp>
Jeff Thompsonf7d49942013-08-01 16:47:40 -070025#if defined(BOOST_TT_HAS_CONFORMING_IS_CLASS_IMPLEMENTATION)
Jeff Thompson2277ce52013-08-01 17:34:11 -070026# include <ndnboost/type_traits/is_class.hpp>
27# include <ndnboost/type_traits/is_union.hpp>
Jeff Thompsonf7d49942013-08-01 16:47:40 -070028#endif
29#endif
30
31// should be the last #include
Jeff Thompson2277ce52013-08-01 17:34:11 -070032#include <ndnboost/type_traits/detail/bool_trait_def.hpp>
Jeff Thompsonf7d49942013-08-01 16:47:40 -070033
34namespace ndnboost {
35
36#ifndef BOOST_IS_ENUM
37#if !(defined(__BORLANDC__) && (__BORLANDC__ <= 0x551))
38
39namespace detail {
40
41#if defined(BOOST_TT_HAS_CONFORMING_IS_CLASS_IMPLEMENTATION)
42
43template <typename T>
44struct is_class_or_union
45{
46 BOOST_STATIC_CONSTANT(bool, value =
47 (::ndnboost::type_traits::ice_or<
48 ::ndnboost::is_class<T>::value
49 , ::ndnboost::is_union<T>::value
50 >::value));
51};
52
53#else
54
55template <typename T>
56struct is_class_or_union
57{
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);
60# else
61 template <class U> static ::ndnboost::type_traits::yes_type is_class_or_union_tester(void(U::*)(void));
62
63# if BOOST_WORKAROUND(BOOST_MSVC, == 1300) \
64 || BOOST_WORKAROUND(__MWERKS__, <= 0x3000) // no SFINAE
65 static ::ndnboost::type_traits::no_type is_class_or_union_tester(...);
66 BOOST_STATIC_CONSTANT(
67 bool, value = sizeof(is_class_or_union_tester(0)) == sizeof(::ndnboost::type_traits::yes_type));
68# else
69 template <class U>
70 static ::ndnboost::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(::ndnboost::type_traits::yes_type));
73# endif
74# endif
75};
76#endif
77
78struct int_convertible
79{
80 int_convertible(int);
81};
82
83// Don't evaluate convertibility to int_convertible unless the type
84// is non-arithmetic. This suppresses warnings with GCC.
85template <bool is_typename_arithmetic_or_reference = true>
86struct is_enum_helper
87{
88 template <typename T> struct type
89 {
90 BOOST_STATIC_CONSTANT(bool, value = false);
91 };
92};
93
94template <>
95struct is_enum_helper<false>
96{
97 template <typename T> struct type
98 : public ::ndnboost::is_convertible<typename ndnboost::add_reference<T>::type,::ndnboost::detail::int_convertible>
99 {
100 };
101};
102
103template <typename T> struct is_enum_impl
104{
105 //typedef ::ndnboost::add_reference<T> ar_t;
106 //typedef typename ar_t::type r_type;
107
108#if defined(__GNUC__)
109
110#ifdef BOOST_TT_HAS_CONFORMING_IS_CLASS_IMPLEMENTATION
111
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 (::ndnboost::type_traits::ice_or<
117 ::ndnboost::is_arithmetic<T>::value
118 , ::ndnboost::is_reference<T>::value
119 , ::ndnboost::is_function<T>::value
120 , is_class_or_union<T>::value
121 , is_array<T>::value
122 >::value));
123#else
124 // ...however, not checking is_class_or_union on non-conforming
125 // compilers prevents a dependency recursion.
126 BOOST_STATIC_CONSTANT(bool, selector =
127 (::ndnboost::type_traits::ice_or<
128 ::ndnboost::is_arithmetic<T>::value
129 , ::ndnboost::is_reference<T>::value
130 , ::ndnboost::is_function<T>::value
131 , is_array<T>::value
132 >::value));
133#endif // BOOST_TT_HAS_CONFORMING_IS_CLASS_IMPLEMENTATION
134
135#else // !defined(__GNUC__):
136
137 BOOST_STATIC_CONSTANT(bool, selector =
138 (::ndnboost::type_traits::ice_or<
139 ::ndnboost::is_arithmetic<T>::value
140 , ::ndnboost::is_reference<T>::value
141 , is_class_or_union<T>::value
142 , is_array<T>::value
143 >::value));
144
145#endif
146
147#if BOOST_WORKAROUND(__BORLANDC__, < 0x600)
148 typedef ::ndnboost::detail::is_enum_helper<
149 ::ndnboost::detail::is_enum_impl<T>::selector
150 > se_t;
151#else
152 typedef ::ndnboost::detail::is_enum_helper<selector> se_t;
153#endif
154
155 typedef typename se_t::template type<T> helper;
156 BOOST_STATIC_CONSTANT(bool, value = helper::value);
157};
158
159// these help on compilers with no partial specialization support:
160BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_enum,void,false)
161#ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS
162BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_enum,void const,false)
163BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_enum,void volatile,false)
164BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_enum,void const volatile,false)
165#endif
166
167} // namespace detail
168
169BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_enum,T,::ndnboost::detail::is_enum_impl<T>::value)
170
171#else // __BORLANDC__
172//
173// buggy is_convertible prevents working
174// implementation of is_enum:
175BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_enum,T,false)
176
177#endif
178
179#else // BOOST_IS_ENUM
180
181BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_enum,T,BOOST_IS_ENUM(T))
182
183#endif
184
185} // namespace ndnboost
186
Jeff Thompson2277ce52013-08-01 17:34:11 -0700187#include <ndnboost/type_traits/detail/bool_trait_undef.hpp>
Jeff Thompsonf7d49942013-08-01 16:47:40 -0700188
189#endif // BOOST_TT_IS_ENUM_HPP_INCLUDED