]> git.donarmstrong.com Git - rsem.git/blob - boost/type_traits/is_empty.hpp
45c4e9e1eeb610314931b23fa9fc17e1e98eb954
[rsem.git] / 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
40 #ifdef BOOST_MSVC
41 #pragma warning(push)
42 #pragma warning(disable:4624) // destructor could not be generated
43 #endif
44
45 template <typename T>
46 struct empty_helper_t1 : public T
47 {
48     empty_helper_t1();  // hh compiler bug workaround
49     int i[256];
50 private:
51    // suppress compiler warnings:
52    empty_helper_t1(const empty_helper_t1&);
53    empty_helper_t1& operator=(const empty_helper_t1&);
54 };
55
56 #ifdef BOOST_MSVC
57 #pragma warning(pop)
58 #endif
59
60 struct empty_helper_t2 { int i[256]; };
61
62 #if !BOOST_WORKAROUND(__BORLANDC__, < 0x600)
63
64 template <typename T, bool is_a_class = false>
65 struct empty_helper
66 {
67     BOOST_STATIC_CONSTANT(bool, value = false);
68 };
69
70 template <typename T>
71 struct empty_helper<T, true>
72 {
73     BOOST_STATIC_CONSTANT(
74         bool, value = (sizeof(empty_helper_t1<T>) == sizeof(empty_helper_t2))
75         );
76 };
77
78 template <typename T>
79 struct is_empty_impl
80 {
81     typedef typename remove_cv<T>::type cvt;
82     BOOST_STATIC_CONSTANT(
83         bool, value = (
84             ::boost::type_traits::ice_or<
85               ::boost::detail::empty_helper<cvt,::boost::is_class<T>::value>::value
86               , BOOST_IS_EMPTY(cvt)
87             >::value
88             ));
89 };
90
91 #else // __BORLANDC__
92
93 template <typename T, bool is_a_class, bool convertible_to_int>
94 struct empty_helper
95 {
96     BOOST_STATIC_CONSTANT(bool, value = false);
97 };
98
99 template <typename T>
100 struct empty_helper<T, true, false>
101 {
102     BOOST_STATIC_CONSTANT(bool, value = (
103         sizeof(empty_helper_t1<T>) == sizeof(empty_helper_t2)
104         ));
105 };
106
107 template <typename T>
108 struct is_empty_impl
109 {
110    typedef typename remove_cv<T>::type cvt;
111    typedef typename add_reference<T>::type r_type;
112
113    BOOST_STATIC_CONSTANT(
114        bool, value = (
115            ::boost::type_traits::ice_or<
116               ::boost::detail::empty_helper<
117                   cvt
118                 , ::boost::is_class<T>::value
119                 , ::boost::is_convertible< r_type,int>::value
120               >::value
121               , BOOST_IS_EMPTY(cvt)
122            >::value));
123 };
124
125 #endif // __BORLANDC__
126
127 #else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
128
129 #ifdef BOOST_MSVC6_MEMBER_TEMPLATES
130
131 template <typename T>
132 struct empty_helper_t1 : public T
133 {
134    empty_helper_t1();
135    int i[256];
136 };
137
138 struct empty_helper_t2 { int i[256]; };
139
140 template <typename T>
141 struct empty_helper_base
142 {
143    enum { value = (sizeof(empty_helper_t1<T>) == sizeof(empty_helper_t2)) };
144 };
145
146 template <typename T>
147 struct empty_helper_nonbase
148 {
149    enum { value = false };
150 };
151
152 template <bool base>
153 struct empty_helper_chooser
154 {
155    template <typename T> struct result_
156    {
157       typedef empty_helper_nonbase<T> type;
158    };
159 };
160
161 template <>
162 struct empty_helper_chooser<true>
163 {
164    template <typename T> struct result_
165    {
166       typedef empty_helper_base<T> type;
167    };
168 };
169
170 template <typename T>
171 struct is_empty_impl
172 {
173    typedef ::boost::detail::empty_helper_chooser<
174       ::boost::type_traits::ice_and<
175          ::boost::type_traits::ice_not< ::boost::is_reference<T>::value >::value,
176          ::boost::type_traits::ice_not< ::boost::is_convertible<T,double>::value >::value,
177          ::boost::type_traits::ice_not< ::boost::is_pointer<T>::value >::value,
178          ::boost::type_traits::ice_not< ::boost::is_member_pointer<T>::value >::value,
179          ::boost::type_traits::ice_not< ::boost::is_array<T>::value >::value,
180          ::boost::type_traits::ice_not< ::boost::is_void<T>::value >::value,
181          ::boost::type_traits::ice_not<
182             ::boost::is_convertible<T,void const volatile*>::value
183             >::value
184       >::value > chooser;
185
186    typedef typename chooser::template result_<T> result;
187    typedef typename result::type eh_type;
188
189    BOOST_STATIC_CONSTANT(bool, value =
190       (::boost::type_traits::ice_or<eh_type::value, BOOST_IS_EMPTY(T)>::value));
191 };
192
193 #else
194
195 template <typename T> struct is_empty_impl
196 {
197     BOOST_STATIC_CONSTANT(bool, value = BOOST_IS_EMPTY(T));
198 };
199
200 #endif  // BOOST_MSVC6_MEMBER_TEMPLATES
201
202 #endif  // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
203
204 // these help when the compiler has no partial specialization support:
205 BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_empty,void,false)
206 #ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS
207 BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_empty,void const,false)
208 BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_empty,void volatile,false)
209 BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_empty,void const volatile,false)
210 #endif
211
212 } // namespace detail
213
214 BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_empty,T,::boost::detail::is_empty_impl<T>::value)
215
216 } // namespace boost
217
218 #include <boost/type_traits/detail/bool_trait_undef.hpp>
219
220 #endif // BOOST_TT_IS_EMPTY_HPP_INCLUDED
221