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
42 #pragma warning(disable:4624) // destructor could not be generated
46 struct empty_helper_t1 : public T
48 empty_helper_t1(); // hh compiler bug workaround
51 // suppress compiler warnings:
52 empty_helper_t1(const empty_helper_t1&);
53 empty_helper_t1& operator=(const empty_helper_t1&);
60 struct empty_helper_t2 { int i[256]; };
62 #if !BOOST_WORKAROUND(__BORLANDC__, < 0x600)
64 template <typename T, bool is_a_class = false>
67 BOOST_STATIC_CONSTANT(bool, value = false);
71 struct empty_helper<T, true>
73 BOOST_STATIC_CONSTANT(
74 bool, value = (sizeof(empty_helper_t1<T>) == sizeof(empty_helper_t2))
81 typedef typename remove_cv<T>::type cvt;
82 BOOST_STATIC_CONSTANT(
84 ::boost::type_traits::ice_or<
85 ::boost::detail::empty_helper<cvt,::boost::is_class<T>::value>::value
93 template <typename T, bool is_a_class, bool convertible_to_int>
96 BOOST_STATIC_CONSTANT(bool, value = false);
100 struct empty_helper<T, true, false>
102 BOOST_STATIC_CONSTANT(bool, value = (
103 sizeof(empty_helper_t1<T>) == sizeof(empty_helper_t2)
107 template <typename T>
110 typedef typename remove_cv<T>::type cvt;
111 typedef typename add_reference<T>::type r_type;
113 BOOST_STATIC_CONSTANT(
115 ::boost::type_traits::ice_or<
116 ::boost::detail::empty_helper<
118 , ::boost::is_class<T>::value
119 , ::boost::is_convertible< r_type,int>::value
121 , BOOST_IS_EMPTY(cvt)
125 #endif // __BORLANDC__
127 #else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
129 #ifdef BOOST_MSVC6_MEMBER_TEMPLATES
131 template <typename T>
132 struct empty_helper_t1 : public T
138 struct empty_helper_t2 { int i[256]; };
140 template <typename T>
141 struct empty_helper_base
143 enum { value = (sizeof(empty_helper_t1<T>) == sizeof(empty_helper_t2)) };
146 template <typename T>
147 struct empty_helper_nonbase
149 enum { value = false };
153 struct empty_helper_chooser
155 template <typename T> struct result_
157 typedef empty_helper_nonbase<T> type;
162 struct empty_helper_chooser<true>
164 template <typename T> struct result_
166 typedef empty_helper_base<T> type;
170 template <typename T>
173 typedef ::boost::detail::empty_helper_chooser<
174 ::boost::type_traits::ice_and<
175 ::boost::type_traits::ice_not< ::boost::is_reference<T>::value >::value,
176 ::boost::type_traits::ice_not< ::boost::is_convertible<T,double>::value >::value,
177 ::boost::type_traits::ice_not< ::boost::is_pointer<T>::value >::value,
178 ::boost::type_traits::ice_not< ::boost::is_member_pointer<T>::value >::value,
179 ::boost::type_traits::ice_not< ::boost::is_array<T>::value >::value,
180 ::boost::type_traits::ice_not< ::boost::is_void<T>::value >::value,
181 ::boost::type_traits::ice_not<
182 ::boost::is_convertible<T,void const volatile*>::value
186 typedef typename chooser::template result_<T> result;
187 typedef typename result::type eh_type;
189 BOOST_STATIC_CONSTANT(bool, value =
190 (::boost::type_traits::ice_or<eh_type::value, BOOST_IS_EMPTY(T)>::value));
195 template <typename T> struct is_empty_impl
197 BOOST_STATIC_CONSTANT(bool, value = BOOST_IS_EMPTY(T));
200 #endif // BOOST_MSVC6_MEMBER_TEMPLATES
202 #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
204 // these help when the compiler has no partial specialization support:
205 BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_empty,void,false)
206 #ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS
207 BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_empty,void const,false)
208 BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_empty,void volatile,false)
209 BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_empty,void const volatile,false)
212 } // namespace detail
214 BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_empty,T,::boost::detail::is_empty_impl<T>::value)
218 #include <boost/type_traits/detail/bool_trait_undef.hpp>
220 #endif // BOOST_TT_IS_EMPTY_HPP_INCLUDED