comparison DEPENDENCIES/generic/include/boost/serialization/smart_cast.hpp @ 101:c530137014c0

Update Boost headers (1.58.0)
author Chris Cannam
date Mon, 07 Sep 2015 11:12:49 +0100
parents 2665513ce2d3
children
comparison
equal deleted inserted replaced
100:793467b5e61c 101:c530137014c0
1 #ifndef BOOST_SERIALIZATION_SMART_CAST_HPP 1 #ifndef BOOST_SERIALIZATION_SMART_CAST_HPP
2 #define BOOST_SERIALIZATION_SMART_CAST_HPP 2 #define BOOST_SERIALIZATION_SMART_CAST_HPP
3 3
4 // MS compatible compilers support #pragma once 4 // MS compatible compilers support #pragma once
5 #if defined(_MSC_VER) && (_MSC_VER >= 1020) 5 #if defined(_MSC_VER)
6 # pragma once 6 # pragma once
7 #endif 7 #endif
8 8
9 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 9 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
10 // smart_cast.hpp: 10 // smart_cast.hpp:
93 // borland 5.51 chokes here so we can't use it 93 // borland 5.51 chokes here so we can't use it
94 // note: if remove_reference isn't function for these types 94 // note: if remove_reference isn't function for these types
95 // cross casting will be selected this will work but will 95 // cross casting will be selected this will work but will
96 // not be the most efficient method. This will conflict with 96 // not be the most efficient method. This will conflict with
97 // the original smart_cast motivation. 97 // the original smart_cast motivation.
98 typedef BOOST_DEDUCED_TYPENAME mpl::eval_if< 98 typedef typename mpl::eval_if<
99 BOOST_DEDUCED_TYPENAME mpl::and_< 99 typename mpl::and_<
100 mpl::not_<is_base_and_derived< 100 mpl::not_<is_base_and_derived<
101 BOOST_DEDUCED_TYPENAME remove_reference< T >::type, 101 typename remove_reference< T >::type,
102 U 102 U
103 > >, 103 > >,
104 mpl::not_<is_base_and_derived< 104 mpl::not_<is_base_and_derived<
105 U, 105 U,
106 BOOST_DEDUCED_TYPENAME remove_reference< T >::type 106 typename remove_reference< T >::type
107 > > 107 > >
108 >, 108 >,
109 // borland chokes w/o full qualification here 109 // borland chokes w/o full qualification here
110 mpl::identity<cross>, 110 mpl::identity<cross>,
111 mpl::identity<linear> 111 mpl::identity<linear>
129 boost::is_polymorphic<U>, 129 boost::is_polymorphic<U>,
130 mpl::identity<polymorphic>, 130 mpl::identity<polymorphic>,
131 mpl::identity<non_polymorphic> 131 mpl::identity<non_polymorphic>
132 >::type::cast(u); 132 >::type::cast(u);
133 #else 133 #else
134 typedef BOOST_DEDUCED_TYPENAME mpl::eval_if< 134 typedef typename mpl::eval_if<
135 boost::is_polymorphic<U>, 135 boost::is_polymorphic<U>,
136 mpl::identity<polymorphic>, 136 mpl::identity<polymorphic>,
137 mpl::identity<non_polymorphic> 137 mpl::identity<non_polymorphic>
138 >::type typex; 138 >::type typex;
139 return typex::cast(u); 139 return typex::cast(u);
168 }; 168 };
169 169
170 template<class U> 170 template<class U>
171 static T cast(U * u){ 171 static T cast(U * u){
172 // if we're in debug mode 172 // if we're in debug mode
173 #if ! defined(NDEBUG) || defined(__BORLANDC__) && (__BORLANDC__ <= 0x560) 173 #if 0 //! defined(NDEBUG) || defined(__BORLANDC__) && (__BORLANDC__ <= 0x560)
174 // do a checked dynamic cast 174 // do a checked dynamic cast
175 return cross::cast(u); 175 return cross::cast(u);
176 #else 176 #else
177 // borland 5.51 chokes here so we can't use it 177 // borland 5.51 chokes here so we can't use it
178 // note: if remove_pointer isn't function for these types 178 // note: if remove_pointer isn't function for these types
179 // cross casting will be selected this will work but will 179 // cross casting will be selected this will work but will
180 // not be the most efficient method. This will conflict with 180 // not be the most efficient method. This will conflict with
181 // the original smart_cast motivation. 181 // the original smart_cast motivation.
182 typedef 182 typedef
183 BOOST_DEDUCED_TYPENAME mpl::eval_if< 183 typename mpl::eval_if<
184 BOOST_DEDUCED_TYPENAME mpl::and_< 184 typename mpl::and_<
185 mpl::not_<is_base_and_derived< 185 mpl::not_<is_base_and_derived<
186 BOOST_DEDUCED_TYPENAME remove_pointer< T >::type, 186 typename remove_pointer< T >::type,
187 U 187 U
188 > >, 188 > >,
189 mpl::not_<is_base_and_derived< 189 mpl::not_<is_base_and_derived<
190 U, 190 U,
191 BOOST_DEDUCED_TYPENAME remove_pointer< T >::type 191 typename remove_pointer< T >::type
192 > > 192 > >
193 >, 193 >,
194 // borland chokes w/o full qualification here 194 // borland chokes w/o full qualification here
195 mpl::identity<cross>, 195 mpl::identity<cross>,
196 mpl::identity<linear> 196 mpl::identity<linear>
224 boost::is_polymorphic<U>, 224 boost::is_polymorphic<U>,
225 mpl::identity<polymorphic>, 225 mpl::identity<polymorphic>,
226 mpl::identity<non_polymorphic> 226 mpl::identity<non_polymorphic>
227 >::type::cast(u); 227 >::type::cast(u);
228 #else 228 #else
229 typedef BOOST_DEDUCED_TYPENAME mpl::eval_if< 229 typedef typename mpl::eval_if<
230 boost::is_polymorphic<U>, 230 boost::is_polymorphic<U>,
231 mpl::identity<polymorphic>, 231 mpl::identity<polymorphic>,
232 mpl::identity<non_polymorphic> 232 mpl::identity<non_polymorphic>
233 >::type typex; 233 >::type typex;
234 return typex::cast(u); 234 return typex::cast(u);
265 // note that it will fail with 265 // note that it will fail with
266 // smart_cast<Target &>(s) 266 // smart_cast<Target &>(s)
267 template<class T, class U> 267 template<class T, class U>
268 T smart_cast(U u) { 268 T smart_cast(U u) {
269 typedef 269 typedef
270 BOOST_DEDUCED_TYPENAME mpl::eval_if< 270 typename mpl::eval_if<
271 BOOST_DEDUCED_TYPENAME mpl::or_< 271 typename mpl::or_<
272 boost::is_same<void *, U>, 272 boost::is_same<void *, U>,
273 boost::is_same<void *, T>, 273 boost::is_same<void *, T>,
274 boost::is_same<const void *, U>, 274 boost::is_same<const void *, U>,
275 boost::is_same<const void *, T> 275 boost::is_same<const void *, T>
276 >, 276 >,
277 mpl::identity<smart_cast_impl::void_pointer< T > >, 277 mpl::identity<smart_cast_impl::void_pointer< T > >,
278 // else 278 // else
279 BOOST_DEDUCED_TYPENAME mpl::eval_if<boost::is_pointer<U>, 279 typename mpl::eval_if<boost::is_pointer<U>,
280 mpl::identity<smart_cast_impl::pointer< T > >, 280 mpl::identity<smart_cast_impl::pointer< T > >,
281 // else 281 // else
282 BOOST_DEDUCED_TYPENAME mpl::eval_if<boost::is_reference<U>, 282 typename mpl::eval_if<boost::is_reference<U>,
283 mpl::identity<smart_cast_impl::reference< T > >, 283 mpl::identity<smart_cast_impl::reference< T > >,
284 // else 284 // else
285 mpl::identity<smart_cast_impl::error< T > 285 mpl::identity<smart_cast_impl::error< T >
286 > 286 >
287 > 287 >