]> git.lyx.org Git - lyx.git/blob - boost/boost/type_traits/is_empty.hpp
update boost to pre-1.30.0
[lyx.git] / boost / boost / type_traits / is_empty.hpp
1
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.
7 //
8 // See http://www.boost.org for most recent version including documentation.
9
10 #ifndef BOOST_TT_IS_EMPTY_HPP_INCLUDED
11 #define BOOST_TT_IS_EMPTY_HPP_INCLUDED
12
13 #include "boost/type_traits/is_convertible.hpp"
14 #include "boost/type_traits/detail/ice_or.hpp"
15 #include "boost/type_traits/config.hpp"
16 #include "boost/type_traits/intrinsics.hpp"
17
18 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
19 #   include "boost/type_traits/remove_cv.hpp"
20 #   include "boost/type_traits/is_class.hpp"
21 #   include "boost/type_traits/add_reference.hpp"
22 #else
23 #   include "boost/type_traits/is_reference.hpp"
24 #   include "boost/type_traits/is_pointer.hpp"
25 #   include "boost/type_traits/is_member_pointer.hpp"
26 #   include "boost/type_traits/is_array.hpp"
27 #   include "boost/type_traits/is_void.hpp"
28 #   include "boost/type_traits/detail/ice_and.hpp"
29 #   include "boost/type_traits/detail/ice_not.hpp"
30 #endif
31
32 // should be always the last #include directive
33 #include "boost/type_traits/detail/bool_trait_def.hpp"
34
35 namespace boost {
36
37 namespace detail {
38
39 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
40 template <typename T>
41 struct empty_helper_t1 : public T
42 {
43     empty_helper_t1();  // hh compiler bug workaround
44     int i[256];
45 };
46
47 struct empty_helper_t2 { int i[256]; };
48
49 #ifndef __BORLANDC__
50
51 template <typename T, bool is_a_class = false>
52 struct empty_helper
53 {
54     BOOST_STATIC_CONSTANT(bool, value = false);
55 };
56
57 template <typename T>
58 struct empty_helper<T, true>
59 {
60     BOOST_STATIC_CONSTANT(
61         bool, value = (sizeof(empty_helper_t1<T>) == sizeof(empty_helper_t2))
62         );
63 };
64
65 template <typename T>
66 struct is_empty_impl
67 {
68     typedef typename remove_cv<T>::type cvt;
69     BOOST_STATIC_CONSTANT(
70         bool, value = (
71             ::boost::type_traits::ice_or<
72               ::boost::detail::empty_helper<cvt,::boost::is_class<T>::value>::value
73               , BOOST_IS_EMPTY(cvt)
74             >::value
75             ));
76 };
77
78 #else // __BORLANDC__
79
80 template <typename T, bool is_a_class, bool convertible_to_int>
81 struct empty_helper
82 {
83     BOOST_STATIC_CONSTANT(bool, value = false);
84 };
85
86 template <typename T>
87 struct empty_helper<T, true, false>
88 {
89     BOOST_STATIC_CONSTANT(bool, value = (
90         sizeof(empty_helper_t1<T>) == sizeof(empty_helper_t2)
91         ));
92 };
93
94 template <typename T>
95 struct is_empty_impl
96 {
97    typedef typename remove_cv<T>::type cvt;
98    typedef typename add_reference<T>::type r_type;
99
100    BOOST_STATIC_CONSTANT(
101        bool, value = (
102            ::boost::type_traits::ice_or<
103               ::boost::detail::empty_helper<
104                   cvt
105                 , ::boost::is_class<T>::value
106                 , ::boost::is_convertible< r_type,int>::value
107               >::value
108               , BOOST_IS_EMPTY(cvt)
109            >::value));
110 };
111
112 #endif // __BORLANDC__
113
114 #else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
115
116 #ifdef BOOST_MSVC6_MEMBER_TEMPLATES
117
118 template <typename T>
119 struct empty_helper_t1 : public T
120 {
121    empty_helper_t1();
122    int i[256];
123 };
124
125 struct empty_helper_t2 { int i[256]; };
126
127 template <typename T>
128 struct empty_helper_base
129 {
130    enum { value = (sizeof(empty_helper_t1<T>) == sizeof(empty_helper_t2)) };
131 };
132
133 template <typename T>
134 struct empty_helper_nonbase
135 {
136    enum { value = false };
137 };
138
139 template <bool base>
140 struct empty_helper_chooser
141 {
142    template <typename T> struct result_
143    {
144       typedef empty_helper_nonbase<T> type;
145    };
146 };
147
148 template <>
149 struct empty_helper_chooser<true>
150 {
151    template <typename T> struct result_
152    {
153       typedef empty_helper_base<T> type;
154    };
155 };
156
157 template <typename T> 
158 struct is_empty_impl
159
160    typedef ::boost::detail::empty_helper_chooser<
161       ::boost::type_traits::ice_and<
162          ::boost::type_traits::ice_not< ::boost::is_reference<T>::value >::value,
163          ::boost::type_traits::ice_not< ::boost::is_convertible<T,double>::value >::value,
164          ::boost::type_traits::ice_not< ::boost::is_pointer<T>::value >::value,
165          ::boost::type_traits::ice_not< ::boost::is_member_pointer<T>::value >::value,
166          ::boost::type_traits::ice_not< ::boost::is_array<T>::value >::value,
167          ::boost::type_traits::ice_not< ::boost::is_void<T>::value >::value,
168          ::boost::type_traits::ice_not<
169             ::boost::is_convertible<T,void const volatile*>::value
170             >::value
171       >::value > chooser;
172
173    typedef typename chooser::template result_<T> result;
174    typedef typename result::type eh_type;
175
176    BOOST_STATIC_CONSTANT(bool, value =
177       (::boost::type_traits::ice_or<eh_type::value, BOOST_IS_EMPTY(T)>::value)); 
178 };
179
180 #else
181
182 template <typename T> struct is_empty_impl
183 {
184     BOOST_STATIC_CONSTANT(bool, value = BOOST_IS_EMPTY(T));
185 };
186
187 #endif  // BOOST_MSVC6_MEMBER_TEMPLATES
188
189 #endif  // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
190
191 // these help when the compiler has no partial specialization support:
192 BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_empty,void,false)
193 #ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS
194 BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_empty,void const,false)
195 BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_empty,void volatile,false)
196 BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_empty,void const volatile,false)
197 #endif
198
199 } // namespace detail
200
201 BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_empty,T,::boost::detail::is_empty_impl<T>::value)
202
203 } // namespace boost
204
205 #include "boost/type_traits/detail/bool_trait_undef.hpp"
206
207 #endif // BOOST_TT_IS_EMPTY_HPP_INCLUDED
208