]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/lambda/test/cast_test.cpp
1 // cast_tests.cpp -- The Boost Lambda Library ------------------
3 // Copyright (C) 2000-2003 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
4 // Copyright (C) 2000-2003 Gary Powell (powellg@amazon.com)
6 // Distributed under the Boost Software License, Version 1.0. (See
7 // accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
10 // For more information, see www.boost.org
12 // -----------------------------------------------------------------------
15 #include <boost/core/lightweight_test.hpp>
16 #define BOOST_CHECK BOOST_TEST
19 #include "boost/lambda/lambda.hpp"
21 #include "boost/lambda/casts.hpp"
25 using namespace boost::lambda
;
31 virtual std::string
class_name() const { return "const base"; }
32 virtual std::string
class_name() { return "base"; }
36 class derived
: public base
{
39 virtual std::string
class_name() const { return "const derived"; }
40 virtual std::string
class_name() { return "derived"; }
48 derived
*p_derived
= new derived
;
49 base
*p_base
= new base
;
54 (var(b
) = ll_static_cast
<base
*>(p_derived
))();
55 (var(d
) = ll_static_cast
<derived
*>(b
))();
57 BOOST_CHECK(b
->class_name() == "derived");
58 BOOST_CHECK(d
->class_name() == "derived");
60 (var(b
) = ll_dynamic_cast
<derived
*>(b
))();
62 BOOST_CHECK(b
->class_name() == "derived");
64 (var(d
) = ll_dynamic_cast
<derived
*>(p_base
))();
69 const derived
* p_const_derived
= p_derived
;
71 BOOST_CHECK(p_const_derived
->class_name() == "const derived");
72 (var(d
) = ll_const_cast
<derived
*>(p_const_derived
))();
73 BOOST_CHECK(d
->class_name() == "derived");
76 char* cp
= reinterpret_cast<char*>(&i
);
79 (var(ip
) = ll_reinterpret_cast
<int *>(cp
))();
80 BOOST_CHECK(*ip
== 10);
85 BOOST_CHECK(string(ll_typeid(d
)().name()) == string(typeid(d
).name()));
90 BOOST_CHECK(ll_sizeof(_1
)(p_derived
) == sizeof(p_derived
));
91 BOOST_CHECK(ll_sizeof(_1
)(*p_derived
) == sizeof(*p_derived
));
92 BOOST_CHECK(ll_sizeof(_1
)(p_base
) == sizeof(p_base
));
93 BOOST_CHECK(ll_sizeof(_1
)(*p_base
) == sizeof(*p_base
));
96 BOOST_CHECK(ll_sizeof(_1
)(an_array
) == 100 * sizeof(int));
107 return boost::report_errors();