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>
34 #ifndef BOOST_INTERNAL_IS_EMPTY
35 #define BOOST_INTERNAL_IS_EMPTY(T) false
37 #define BOOST_INTERNAL_IS_EMPTY(T) BOOST_IS_EMPTY(T)
44 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
48 #pragma warning(disable:4624) // destructor could not be generated
52 struct empty_helper_t1 : public T
54 empty_helper_t1(); // hh compiler bug workaround
57 // suppress compiler warnings:
58 empty_helper_t1(const empty_helper_t1&);
59 empty_helper_t1& operator=(const empty_helper_t1&);
66 struct empty_helper_t2 { int i[256]; };
68 #if !BOOST_WORKAROUND(__BORLANDC__, < 0x600)
70 template <typename T, bool is_a_class = false>
73 BOOST_STATIC_CONSTANT(bool, value = false);
77 struct empty_helper<T, true>
79 BOOST_STATIC_CONSTANT(
80 bool, value = (sizeof(empty_helper_t1<T>) == sizeof(empty_helper_t2))
87 typedef typename remove_cv<T>::type cvt;
88 BOOST_STATIC_CONSTANT(
90 ::boost::type_traits::ice_or<
91 ::boost::detail::empty_helper<cvt,::boost::is_class<T>::value>::value
92 , BOOST_INTERNAL_IS_EMPTY(cvt)
99 template <typename T, bool is_a_class, bool convertible_to_int>
102 BOOST_STATIC_CONSTANT(bool, value = false);
105 template <typename T>
106 struct empty_helper<T, true, false>
108 BOOST_STATIC_CONSTANT(bool, value = (
109 sizeof(empty_helper_t1<T>) == sizeof(empty_helper_t2)
113 template <typename T>
116 typedef typename remove_cv<T>::type cvt;
117 typedef typename add_reference<T>::type r_type;
119 BOOST_STATIC_CONSTANT(
121 ::boost::type_traits::ice_or<
122 ::boost::detail::empty_helper<
124 , ::boost::is_class<T>::value
125 , ::boost::is_convertible< r_type,int>::value
127 , BOOST_INTERNAL_IS_EMPTY(cvt)
131 #endif // __BORLANDC__
133 #else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
135 #ifdef BOOST_MSVC6_MEMBER_TEMPLATES
137 template <typename T>
138 struct empty_helper_t1 : public T
144 struct empty_helper_t2 { int i[256]; };
146 template <typename T>
147 struct empty_helper_base
149 enum { value = (sizeof(empty_helper_t1<T>) == sizeof(empty_helper_t2)) };
152 template <typename T>
153 struct empty_helper_nonbase
155 enum { value = false };
159 struct empty_helper_chooser
161 template <typename T> struct result_
163 typedef empty_helper_nonbase<T> type;
168 struct empty_helper_chooser<true>
170 template <typename T> struct result_
172 typedef empty_helper_base<T> type;
176 template <typename T>
179 typedef ::boost::detail::empty_helper_chooser<
180 ::boost::type_traits::ice_and<
181 ::boost::type_traits::ice_not< ::boost::is_reference<T>::value >::value,
182 ::boost::type_traits::ice_not< ::boost::is_convertible<T,double>::value >::value,
183 ::boost::type_traits::ice_not< ::boost::is_pointer<T>::value >::value,
184 ::boost::type_traits::ice_not< ::boost::is_member_pointer<T>::value >::value,
185 ::boost::type_traits::ice_not< ::boost::is_array<T>::value >::value,
186 ::boost::type_traits::ice_not< ::boost::is_void<T>::value >::value,
187 ::boost::type_traits::ice_not<
188 ::boost::is_convertible<T,void const volatile*>::value
192 typedef typename chooser::template result_<T> result;
193 typedef typename result::type eh_type;
195 BOOST_STATIC_CONSTANT(bool, value =
196 (::boost::type_traits::ice_or<eh_type::value, BOOST_INTERNAL_IS_EMPTY(T)>::value));
201 template <typename T> struct is_empty_impl
203 BOOST_STATIC_CONSTANT(bool, value = BOOST_INTERNAL_IS_EMPTY(T));
206 #endif // BOOST_MSVC6_MEMBER_TEMPLATES
208 #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
210 // these help when the compiler has no partial specialization support:
211 BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_empty,void,false)
212 #ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS
213 BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_empty,void const,false)
214 BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_empty,void volatile,false)
215 BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_empty,void const volatile,false)
218 } // namespace detail
220 BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_empty,T,::boost::detail::is_empty_impl<T>::value)
224 #include <boost/type_traits/detail/bool_trait_undef.hpp>
226 #undef BOOST_INTERNAL_IS_EMPTY
228 #endif // BOOST_TT_IS_EMPTY_HPP_INCLUDED