Imported Upstream version 0.8~alpha1
[platform/upstream/syncevolution.git] / src / boost / type_traits / is_empty.hpp
1
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).
6 //
7 //  See http://www.boost.org/libs/type_traits for most recent version including documentation.
8
9 #ifndef BOOST_TT_IS_EMPTY_HPP_INCLUDED
10 #define BOOST_TT_IS_EMPTY_HPP_INCLUDED
11
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>
16
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>
21 #else
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>
29 #endif
30
31 // should be always the last #include directive
32 #include <boost/type_traits/detail/bool_trait_def.hpp>
33
34 namespace boost {
35
36 namespace detail {
37
38 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
39 template <typename T>
40 struct empty_helper_t1 : public T
41 {
42     empty_helper_t1();  // hh compiler bug workaround
43     int i[256];
44 private:
45    // suppress compiler warnings:
46    empty_helper_t1(const empty_helper_t1&);
47    empty_helper_t1& operator=(const empty_helper_t1&);
48 };
49
50 struct empty_helper_t2 { int i[256]; };
51
52 #if !BOOST_WORKAROUND(__BORLANDC__, < 0x600)
53
54 template <typename T, bool is_a_class = false>
55 struct empty_helper
56 {
57     BOOST_STATIC_CONSTANT(bool, value = false);
58 };
59
60 template <typename T>
61 struct empty_helper<T, true>
62 {
63     BOOST_STATIC_CONSTANT(
64         bool, value = (sizeof(empty_helper_t1<T>) == sizeof(empty_helper_t2))
65         );
66 };
67
68 template <typename T>
69 struct is_empty_impl
70 {
71     typedef typename remove_cv<T>::type cvt;
72     BOOST_STATIC_CONSTANT(
73         bool, value = (
74             ::boost::type_traits::ice_or<
75               ::boost::detail::empty_helper<cvt,::boost::is_class<T>::value>::value
76               , BOOST_IS_EMPTY(cvt)
77             >::value
78             ));
79 };
80
81 #else // __BORLANDC__
82
83 template <typename T, bool is_a_class, bool convertible_to_int>
84 struct empty_helper
85 {
86     BOOST_STATIC_CONSTANT(bool, value = false);
87 };
88
89 template <typename T>
90 struct empty_helper<T, true, false>
91 {
92     BOOST_STATIC_CONSTANT(bool, value = (
93         sizeof(empty_helper_t1<T>) == sizeof(empty_helper_t2)
94         ));
95 };
96
97 template <typename T>
98 struct is_empty_impl
99 {
100    typedef typename remove_cv<T>::type cvt;
101    typedef typename add_reference<T>::type r_type;
102
103    BOOST_STATIC_CONSTANT(
104        bool, value = (
105            ::boost::type_traits::ice_or<
106               ::boost::detail::empty_helper<
107                   cvt
108                 , ::boost::is_class<T>::value
109                 , ::boost::is_convertible< r_type,int>::value
110               >::value
111               , BOOST_IS_EMPTY(cvt)
112            >::value));
113 };
114
115 #endif // __BORLANDC__
116
117 #else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
118
119 #ifdef BOOST_MSVC6_MEMBER_TEMPLATES
120
121 template <typename T>
122 struct empty_helper_t1 : public T
123 {
124    empty_helper_t1();
125    int i[256];
126 };
127
128 struct empty_helper_t2 { int i[256]; };
129
130 template <typename T>
131 struct empty_helper_base
132 {
133    enum { value = (sizeof(empty_helper_t1<T>) == sizeof(empty_helper_t2)) };
134 };
135
136 template <typename T>
137 struct empty_helper_nonbase
138 {
139    enum { value = false };
140 };
141
142 template <bool base>
143 struct empty_helper_chooser
144 {
145    template <typename T> struct result_
146    {
147       typedef empty_helper_nonbase<T> type;
148    };
149 };
150
151 template <>
152 struct empty_helper_chooser<true>
153 {
154    template <typename T> struct result_
155    {
156       typedef empty_helper_base<T> type;
157    };
158 };
159
160 template <typename T>
161 struct is_empty_impl
162 {
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
173             >::value
174       >::value > chooser;
175
176    typedef typename chooser::template result_<T> result;
177    typedef typename result::type eh_type;
178
179    BOOST_STATIC_CONSTANT(bool, value =
180       (::boost::type_traits::ice_or<eh_type::value, BOOST_IS_EMPTY(T)>::value));
181 };
182
183 #else
184
185 template <typename T> struct is_empty_impl
186 {
187     BOOST_STATIC_CONSTANT(bool, value = BOOST_IS_EMPTY(T));
188 };
189
190 #endif  // BOOST_MSVC6_MEMBER_TEMPLATES
191
192 #endif  // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
193
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)
200 #endif
201
202 } // namespace detail
203
204 BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_empty,T,::boost::detail::is_empty_impl<T>::value)
205
206 } // namespace boost
207
208 #include <boost/type_traits/detail/bool_trait_undef.hpp>
209
210 #endif // BOOST_TT_IS_EMPTY_HPP_INCLUDED
211