2 // (C) Copyright Steve Cleary, Beman Dawes, Howard Hinnant & John Maddock 2000.
3 // Permission to copy, use, modify, sell and distribute this software is
4 // granted provided this copyright notice appears in all copies. This software
5 // is provided "as is" without express or implied warranty, and with no claim
6 // as to its suitability for any purpose.
8 // See http://www.boost.org for most recent version including documentation.
10 #ifndef BOOST_TT_IS_EMPTY_HPP_INCLUDED
11 #define BOOST_TT_IS_EMPTY_HPP_INCLUDED
13 #include "boost/type_traits/is_convertible.hpp"
14 #include "boost/type_traits/detail/ice_or.hpp"
15 #include "boost/type_traits/config.hpp"
16 #include "boost/type_traits/intrinsics.hpp"
18 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
19 # include "boost/type_traits/remove_cv.hpp"
20 # include "boost/type_traits/is_class.hpp"
21 # include "boost/type_traits/add_reference.hpp"
23 # include "boost/type_traits/is_reference.hpp"
24 # include "boost/type_traits/is_pointer.hpp"
25 # include "boost/type_traits/is_member_pointer.hpp"
26 # include "boost/type_traits/is_array.hpp"
27 # include "boost/type_traits/is_void.hpp"
28 # include "boost/type_traits/detail/ice_and.hpp"
29 # include "boost/type_traits/detail/ice_not.hpp"
32 // should be always the last #include directive
33 #include "boost/type_traits/detail/bool_trait_def.hpp"
39 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
41 struct empty_helper_t1 : public T
43 empty_helper_t1(); // hh compiler bug workaround
47 struct empty_helper_t2 { int i[256]; };
51 template <typename T, bool is_a_class = false>
54 BOOST_STATIC_CONSTANT(bool, value = false);
58 struct empty_helper<T, true>
60 BOOST_STATIC_CONSTANT(
61 bool, value = (sizeof(empty_helper_t1<T>) == sizeof(empty_helper_t2))
68 typedef typename remove_cv<T>::type cvt;
69 BOOST_STATIC_CONSTANT(
71 ::boost::type_traits::ice_or<
72 ::boost::detail::empty_helper<cvt,::boost::is_class<T>::value>::value
80 template <typename T, bool is_a_class, bool convertible_to_int>
83 BOOST_STATIC_CONSTANT(bool, value = false);
87 struct empty_helper<T, true, false>
89 BOOST_STATIC_CONSTANT(bool, value = (
90 sizeof(empty_helper_t1<T>) == sizeof(empty_helper_t2)
97 typedef typename remove_cv<T>::type cvt;
98 typedef typename add_reference<T>::type r_type;
100 BOOST_STATIC_CONSTANT(
102 ::boost::type_traits::ice_or<
103 ::boost::detail::empty_helper<
105 , ::boost::is_class<T>::value
106 , ::boost::is_convertible< r_type,int>::value
108 , BOOST_IS_EMPTY(cvt)
112 #endif // __BORLANDC__
114 #else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
116 #ifdef BOOST_MSVC6_MEMBER_TEMPLATES
118 template <typename T>
119 struct empty_helper_t1 : public T
125 struct empty_helper_t2 { int i[256]; };
127 template <typename T>
128 struct empty_helper_base
130 enum { value = (sizeof(empty_helper_t1<T>) == sizeof(empty_helper_t2)) };
133 template <typename T>
134 struct empty_helper_nonbase
136 enum { value = false };
140 struct empty_helper_chooser
142 template <typename T> struct result_
144 typedef empty_helper_nonbase<T> type;
149 struct empty_helper_chooser<true>
151 template <typename T> struct result_
153 typedef empty_helper_base<T> type;
157 template <typename T>
160 typedef ::boost::detail::empty_helper_chooser<
161 ::boost::type_traits::ice_and<
162 ::boost::type_traits::ice_not< ::boost::is_reference<T>::value >::value,
163 ::boost::type_traits::ice_not< ::boost::is_convertible<T,double>::value >::value,
164 ::boost::type_traits::ice_not< ::boost::is_pointer<T>::value >::value,
165 ::boost::type_traits::ice_not< ::boost::is_member_pointer<T>::value >::value,
166 ::boost::type_traits::ice_not< ::boost::is_array<T>::value >::value,
167 ::boost::type_traits::ice_not< ::boost::is_void<T>::value >::value,
168 ::boost::type_traits::ice_not<
169 ::boost::is_convertible<T,void const volatile*>::value
173 typedef typename chooser::template result_<T> result;
174 typedef typename result::type eh_type;
176 BOOST_STATIC_CONSTANT(bool, value =
177 (::boost::type_traits::ice_or<eh_type::value, BOOST_IS_EMPTY(T)>::value));
182 template <typename T> struct is_empty_impl
184 BOOST_STATIC_CONSTANT(bool, value = BOOST_IS_EMPTY(T));
187 #endif // BOOST_MSVC6_MEMBER_TEMPLATES
189 #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
191 // these help when the compiler has no partial specialization support:
192 BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_empty,void,false)
193 #ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS
194 BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_empty,void const,false)
195 BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_empty,void volatile,false)
196 BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_empty,void const volatile,false)
199 } // namespace detail
201 BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_empty,T,::boost::detail::is_empty_impl<T>::value)
205 #include "boost/type_traits/detail/bool_trait_undef.hpp"
207 #endif // BOOST_TT_IS_EMPTY_HPP_INCLUDED