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"
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
46 struct empty_helper_t2 { int i[256]; };
50 template <typename T, bool is_a_class = false>
53 BOOST_STATIC_CONSTANT(bool, value = false);
57 struct empty_helper<T, true>
59 BOOST_STATIC_CONSTANT(
60 bool, value = (sizeof(empty_helper_t1<T>) == sizeof(empty_helper_t2))
67 typedef typename remove_cv<T>::type cvt;
68 BOOST_STATIC_CONSTANT(
70 ::boost::type_traits::ice_or<
71 ::boost::detail::empty_helper<cvt,::boost::is_class<T>::value>::value
79 template <typename T, bool is_a_class, bool convertible_to_int>
82 BOOST_STATIC_CONSTANT(bool, value = false);
86 struct empty_helper<T, true, false>
88 BOOST_STATIC_CONSTANT(bool, value = (
89 sizeof(empty_helper_t1<T>) == sizeof(empty_helper_t2)
96 typedef typename remove_cv<T>::type cvt;
97 typedef typename add_reference<T>::type r_type;
99 BOOST_STATIC_CONSTANT(
101 ::boost::type_traits::ice_or<
102 ::boost::detail::empty_helper<
104 , ::boost::is_class<T>::value
105 , ::boost::is_convertible< r_type,int>::value
107 , BOOST_IS_EMPTY(cvt)
111 #endif // __BORLANDC__
113 #else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
115 #ifdef BOOST_MSVC6_MEMBER_TEMPLATES
117 template <typename T>
118 struct empty_helper_t1 : public T
124 struct empty_helper_t2 { int i[256]; };
126 template <typename T>
127 struct empty_helper_base
129 enum { value = (sizeof(empty_helper_t1<T>) == sizeof(empty_helper_t2)) };
132 template <typename T>
133 struct empty_helper_nonbase
135 enum { value = false };
139 struct empty_helper_chooser
141 template <typename T> struct result_
143 typedef empty_helper_nonbase<T> type;
148 struct empty_helper_chooser<true>
150 template <typename T> struct result_
152 typedef empty_helper_base<T> type;
156 template <typename T>
159 typedef ::boost::detail::empty_helper_chooser<
160 ::boost::type_traits::ice_and<
161 ::boost::type_traits::ice_not< ::boost::is_reference<T>::value >::value,
162 ::boost::type_traits::ice_not< ::boost::is_convertible<T,double>::value >::value,
163 ::boost::type_traits::ice_not< ::boost::is_pointer<T>::value >::value,
164 ::boost::type_traits::ice_not< ::boost::is_member_pointer<T>::value >::value,
165 ::boost::type_traits::ice_not< ::boost::is_array<T>::value >::value,
166 ::boost::type_traits::ice_not< ::boost::is_void<T>::value >::value,
167 ::boost::type_traits::ice_not<
168 ::boost::is_convertible<T,void const volatile*>::value
172 typedef typename chooser::template result_<T> result;
173 typedef typename result::type eh_type;
175 BOOST_STATIC_CONSTANT(bool, value =
176 (::boost::type_traits::ice_or<eh_type::value, BOOST_IS_EMPTY(T)>::value));
181 template <typename T> struct is_empty_impl
183 BOOST_STATIC_CONSTANT(bool, value = BOOST_IS_EMPTY(T));
186 #endif // BOOST_MSVC6_MEMBER_TEMPLATES
188 #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
190 } // namespace detail
192 BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_empty,T,::boost::detail::is_empty_impl<T>::value)
196 #include "boost/type_traits/detail/bool_trait_undef.hpp"
198 #endif // BOOST_TT_IS_EMPTY_HPP_INCLUDED