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 | };
|
---|
45 |
|
---|
46 | struct empty_helper_t2 { int i[256]; };
|
---|
47 |
|
---|
48 | #if !BOOST_WORKAROUND(__BORLANDC__, < 0x600)
|
---|
49 |
|
---|
50 | template <typename T, bool is_a_class = false>
|
---|
51 | struct empty_helper
|
---|
52 | {
|
---|
53 | BOOST_STATIC_CONSTANT(bool, value = false);
|
---|
54 | };
|
---|
55 |
|
---|
56 | template <typename T>
|
---|
57 | struct empty_helper<T, true>
|
---|
58 | {
|
---|
59 | BOOST_STATIC_CONSTANT(
|
---|
60 | bool, value = (sizeof(empty_helper_t1<T>) == sizeof(empty_helper_t2))
|
---|
61 | );
|
---|
62 | };
|
---|
63 |
|
---|
64 | template <typename T>
|
---|
65 | struct is_empty_impl
|
---|
66 | {
|
---|
67 | typedef typename remove_cv<T>::type cvt;
|
---|
68 | BOOST_STATIC_CONSTANT(
|
---|
69 | bool, value = (
|
---|
70 | ::boost::type_traits::ice_or<
|
---|
71 | ::boost::detail::empty_helper<cvt,::boost::is_class<T>::value>::value
|
---|
72 | , BOOST_IS_EMPTY(cvt)
|
---|
73 | >::value
|
---|
74 | ));
|
---|
75 | };
|
---|
76 |
|
---|
77 | #else // __BORLANDC__
|
---|
78 |
|
---|
79 | template <typename T, bool is_a_class, bool convertible_to_int>
|
---|
80 | struct empty_helper
|
---|
81 | {
|
---|
82 | BOOST_STATIC_CONSTANT(bool, value = false);
|
---|
83 | };
|
---|
84 |
|
---|
85 | template <typename T>
|
---|
86 | struct empty_helper<T, true, false>
|
---|
87 | {
|
---|
88 | BOOST_STATIC_CONSTANT(bool, value = (
|
---|
89 | sizeof(empty_helper_t1<T>) == sizeof(empty_helper_t2)
|
---|
90 | ));
|
---|
91 | };
|
---|
92 |
|
---|
93 | template <typename T>
|
---|
94 | struct is_empty_impl
|
---|
95 | {
|
---|
96 | typedef typename remove_cv<T>::type cvt;
|
---|
97 | typedef typename add_reference<T>::type r_type;
|
---|
98 |
|
---|
99 | BOOST_STATIC_CONSTANT(
|
---|
100 | bool, value = (
|
---|
101 | ::boost::type_traits::ice_or<
|
---|
102 | ::boost::detail::empty_helper<
|
---|
103 | cvt
|
---|
104 | , ::boost::is_class<T>::value
|
---|
105 | , ::boost::is_convertible< r_type,int>::value
|
---|
106 | >::value
|
---|
107 | , BOOST_IS_EMPTY(cvt)
|
---|
108 | >::value));
|
---|
109 | };
|
---|
110 |
|
---|
111 | #endif // __BORLANDC__
|
---|
112 |
|
---|
113 | #else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
---|
114 |
|
---|
115 | #ifdef BOOST_MSVC6_MEMBER_TEMPLATES
|
---|
116 |
|
---|
117 | template <typename T>
|
---|
118 | struct empty_helper_t1 : public T
|
---|
119 | {
|
---|
120 | empty_helper_t1();
|
---|
121 | int i[256];
|
---|
122 | };
|
---|
123 |
|
---|
124 | struct empty_helper_t2 { int i[256]; };
|
---|
125 |
|
---|
126 | template <typename T>
|
---|
127 | struct empty_helper_base
|
---|
128 | {
|
---|
129 | enum { value = (sizeof(empty_helper_t1<T>) == sizeof(empty_helper_t2)) };
|
---|
130 | };
|
---|
131 |
|
---|
132 | template <typename T>
|
---|
133 | struct empty_helper_nonbase
|
---|
134 | {
|
---|
135 | enum { value = false };
|
---|
136 | };
|
---|
137 |
|
---|
138 | template <bool base>
|
---|
139 | struct empty_helper_chooser
|
---|
140 | {
|
---|
141 | template <typename T> struct result_
|
---|
142 | {
|
---|
143 | typedef empty_helper_nonbase<T> type;
|
---|
144 | };
|
---|
145 | };
|
---|
146 |
|
---|
147 | template <>
|
---|
148 | struct empty_helper_chooser<true>
|
---|
149 | {
|
---|
150 | template <typename T> struct result_
|
---|
151 | {
|
---|
152 | typedef empty_helper_base<T> type;
|
---|
153 | };
|
---|
154 | };
|
---|
155 |
|
---|
156 | template <typename T>
|
---|
157 | struct is_empty_impl
|
---|
158 | {
|
---|
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
|
---|
169 | >::value
|
---|
170 | >::value > chooser;
|
---|
171 |
|
---|
172 | typedef typename chooser::template result_<T> result;
|
---|
173 | typedef typename result::type eh_type;
|
---|
174 |
|
---|
175 | BOOST_STATIC_CONSTANT(bool, value =
|
---|
176 | (::boost::type_traits::ice_or<eh_type::value, BOOST_IS_EMPTY(T)>::value));
|
---|
177 | };
|
---|
178 |
|
---|
179 | #else
|
---|
180 |
|
---|
181 | template <typename T> struct is_empty_impl
|
---|
182 | {
|
---|
183 | BOOST_STATIC_CONSTANT(bool, value = BOOST_IS_EMPTY(T));
|
---|
184 | };
|
---|
185 |
|
---|
186 | #endif // BOOST_MSVC6_MEMBER_TEMPLATES
|
---|
187 |
|
---|
188 | #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
---|
189 |
|
---|
190 | // these help when the compiler has no partial specialization support:
|
---|
191 | BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_empty,void,false)
|
---|
192 | #ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS
|
---|
193 | BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_empty,void const,false)
|
---|
194 | BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_empty,void volatile,false)
|
---|
195 | BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_empty,void const volatile,false)
|
---|
196 | #endif
|
---|
197 |
|
---|
198 | } // namespace detail
|
---|
199 |
|
---|
200 | BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_empty,T,::boost::detail::is_empty_impl<T>::value)
|
---|
201 |
|
---|
202 | } // namespace boost
|
---|
203 |
|
---|
204 | #include "boost/type_traits/detail/bool_trait_undef.hpp"
|
---|
205 |
|
---|
206 | #endif // BOOST_TT_IS_EMPTY_HPP_INCLUDED
|
---|
207 |
|
---|