2 // (C) Copyright Steve Cleary, Beman Dawes, Howard Hinnant & John Maddock 2000.
3 // Use, modification and distribution are subject to the Boost Software License,
4 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt).
7 // See http://www.boost.org/libs/type_traits for most recent version including documentation.
9 #ifndef BOOST_TT_IS_EMPTY_HPP_INCLUDED
10 #define BOOST_TT_IS_EMPTY_HPP_INCLUDED
12 #include <boost/type_traits/is_convertible.hpp>
13 #include <boost/type_traits/detail/ice_or.hpp>
14 #include <boost/type_traits/config.hpp>
15 #include <boost/type_traits/intrinsics.hpp>
17 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
18 # include <boost/type_traits/remove_cv.hpp>
19 # include <boost/type_traits/is_class.hpp>
20 # include <boost/type_traits/add_reference.hpp>
22 # include <boost/type_traits/is_reference.hpp>
23 # include <boost/type_traits/is_pointer.hpp>
24 # include <boost/type_traits/is_member_pointer.hpp>
25 # include <boost/type_traits/is_array.hpp>
26 # include <boost/type_traits/is_void.hpp>
27 # include <boost/type_traits/detail/ice_and.hpp>
28 # include <boost/type_traits/detail/ice_not.hpp>
31 // should be always the last #include directive
32 #include <boost/type_traits/detail/bool_trait_def.hpp>
38 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
40 struct empty_helper_t1 : public T
42 empty_helper_t1(); // hh compiler bug workaround
45 // suppress compiler warnings:
46 empty_helper_t1(const empty_helper_t1&);
47 empty_helper_t1& operator=(const empty_helper_t1&);
50 struct empty_helper_t2 { int i[256]; };
52 #if !BOOST_WORKAROUND(__BORLANDC__, < 0x600)
54 template <typename T, bool is_a_class = false>
57 BOOST_STATIC_CONSTANT(bool, value = false);
61 struct empty_helper<T, true>
63 BOOST_STATIC_CONSTANT(
64 bool, value = (sizeof(empty_helper_t1<T>) == sizeof(empty_helper_t2))
71 typedef typename remove_cv<T>::type cvt;
72 BOOST_STATIC_CONSTANT(
74 ::boost::type_traits::ice_or<
75 ::boost::detail::empty_helper<cvt,::boost::is_class<T>::value>::value
83 template <typename T, bool is_a_class, bool convertible_to_int>
86 BOOST_STATIC_CONSTANT(bool, value = false);
90 struct empty_helper<T, true, false>
92 BOOST_STATIC_CONSTANT(bool, value = (
93 sizeof(empty_helper_t1<T>) == sizeof(empty_helper_t2)
100 typedef typename remove_cv<T>::type cvt;
101 typedef typename add_reference<T>::type r_type;
103 BOOST_STATIC_CONSTANT(
105 ::boost::type_traits::ice_or<
106 ::boost::detail::empty_helper<
108 , ::boost::is_class<T>::value
109 , ::boost::is_convertible< r_type,int>::value
111 , BOOST_IS_EMPTY(cvt)
115 #endif // __BORLANDC__
117 #else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
119 #ifdef BOOST_MSVC6_MEMBER_TEMPLATES
121 template <typename T>
122 struct empty_helper_t1 : public T
128 struct empty_helper_t2 { int i[256]; };
130 template <typename T>
131 struct empty_helper_base
133 enum { value = (sizeof(empty_helper_t1<T>) == sizeof(empty_helper_t2)) };
136 template <typename T>
137 struct empty_helper_nonbase
139 enum { value = false };
143 struct empty_helper_chooser
145 template <typename T> struct result_
147 typedef empty_helper_nonbase<T> type;
152 struct empty_helper_chooser<true>
154 template <typename T> struct result_
156 typedef empty_helper_base<T> type;
160 template <typename T>
163 typedef ::boost::detail::empty_helper_chooser<
164 ::boost::type_traits::ice_and<
165 ::boost::type_traits::ice_not< ::boost::is_reference<T>::value >::value,
166 ::boost::type_traits::ice_not< ::boost::is_convertible<T,double>::value >::value,
167 ::boost::type_traits::ice_not< ::boost::is_pointer<T>::value >::value,
168 ::boost::type_traits::ice_not< ::boost::is_member_pointer<T>::value >::value,
169 ::boost::type_traits::ice_not< ::boost::is_array<T>::value >::value,
170 ::boost::type_traits::ice_not< ::boost::is_void<T>::value >::value,
171 ::boost::type_traits::ice_not<
172 ::boost::is_convertible<T,void const volatile*>::value
176 typedef typename chooser::template result_<T> result;
177 typedef typename result::type eh_type;
179 BOOST_STATIC_CONSTANT(bool, value =
180 (::boost::type_traits::ice_or<eh_type::value, BOOST_IS_EMPTY(T)>::value));
185 template <typename T> struct is_empty_impl
187 BOOST_STATIC_CONSTANT(bool, value = BOOST_IS_EMPTY(T));
190 #endif // BOOST_MSVC6_MEMBER_TEMPLATES
192 #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
194 // these help when the compiler has no partial specialization support:
195 BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_empty,void,false)
196 #ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS
197 BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_empty,void const,false)
198 BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_empty,void volatile,false)
199 BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_empty,void const volatile,false)
202 } // namespace detail
204 BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_empty,T,::boost::detail::is_empty_impl<T>::value)
208 #include <boost/type_traits/detail/bool_trait_undef.hpp>
210 #endif // BOOST_TT_IS_EMPTY_HPP_INCLUDED