source: NonGTP/Boost/boost/type_traits/is_empty.hpp @ 857

Revision 857, 5.7 KB checked in by igarcia, 18 years ago (diff)
Line 
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
34namespace boost {
35
36namespace detail {
37
38#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
39template <typename T>
40struct empty_helper_t1 : public T
41{
42    empty_helper_t1();  // hh compiler bug workaround
43    int i[256];
44};
45
46struct empty_helper_t2 { int i[256]; };
47
48#if !BOOST_WORKAROUND(__BORLANDC__, < 0x600)
49
50template <typename T, bool is_a_class = false>
51struct empty_helper
52{
53    BOOST_STATIC_CONSTANT(bool, value = false);
54};
55
56template <typename T>
57struct empty_helper<T, true>
58{
59    BOOST_STATIC_CONSTANT(
60        bool, value = (sizeof(empty_helper_t1<T>) == sizeof(empty_helper_t2))
61        );
62};
63
64template <typename T>
65struct 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
79template <typename T, bool is_a_class, bool convertible_to_int>
80struct empty_helper
81{
82    BOOST_STATIC_CONSTANT(bool, value = false);
83};
84
85template <typename T>
86struct 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
93template <typename T>
94struct 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
117template <typename T>
118struct empty_helper_t1 : public T
119{
120   empty_helper_t1();
121   int i[256];
122};
123
124struct empty_helper_t2 { int i[256]; };
125
126template <typename T>
127struct empty_helper_base
128{
129   enum { value = (sizeof(empty_helper_t1<T>) == sizeof(empty_helper_t2)) };
130};
131
132template <typename T>
133struct empty_helper_nonbase
134{
135   enum { value = false };
136};
137
138template <bool base>
139struct empty_helper_chooser
140{
141   template <typename T> struct result_
142   {
143      typedef empty_helper_nonbase<T> type;
144   };
145};
146
147template <>
148struct empty_helper_chooser<true>
149{
150   template <typename T> struct result_
151   {
152      typedef empty_helper_base<T> type;
153   };
154};
155
156template <typename T>
157struct 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
181template <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:
191BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_empty,void,false)
192#ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS
193BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_empty,void const,false)
194BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_empty,void volatile,false)
195BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_empty,void const volatile,false)
196#endif
197
198} // namespace detail
199
200BOOST_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
Note: See TracBrowser for help on using the repository browser.