]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/lambda/test/cast_test.cpp
bump version to 18.2.4-pve3
[ceph.git] / ceph / src / boost / libs / lambda / test / cast_test.cpp
1 // cast_tests.cpp -- The Boost Lambda Library ------------------
2 //
3 // Copyright (C) 2000-2003 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
4 // Copyright (C) 2000-2003 Gary Powell (powellg@amazon.com)
5 //
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)
9 //
10 // For more information, see www.boost.org
11
12 // -----------------------------------------------------------------------
13
14
15 #include <boost/core/lightweight_test.hpp>
16 #define BOOST_CHECK BOOST_TEST
17
18
19 #include "boost/lambda/lambda.hpp"
20
21 #include "boost/lambda/casts.hpp"
22
23 #include <string>
24
25 using namespace boost::lambda;
26 using namespace std;
27
28 class base {
29 int x;
30 public:
31 virtual std::string class_name() const { return "const base"; }
32 virtual std::string class_name() { return "base"; }
33 virtual ~base() {}
34 };
35
36 class derived : public base {
37 int y[100];
38 public:
39 virtual std::string class_name() const { return "const derived"; }
40 virtual std::string class_name() { return "derived"; }
41 };
42
43
44
45
46 void do_test() {
47
48 derived *p_derived = new derived;
49 base *p_base = new base;
50
51 base *b = 0;
52 derived *d = 0;
53
54 (var(b) = ll_static_cast<base *>(p_derived))();
55 (var(d) = ll_static_cast<derived *>(b))();
56
57 BOOST_CHECK(b->class_name() == "derived");
58 BOOST_CHECK(d->class_name() == "derived");
59
60 (var(b) = ll_dynamic_cast<derived *>(b))();
61 BOOST_CHECK(b != 0);
62 BOOST_CHECK(b->class_name() == "derived");
63
64 (var(d) = ll_dynamic_cast<derived *>(p_base))();
65 BOOST_CHECK(d == 0);
66
67
68
69 const derived* p_const_derived = p_derived;
70
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");
74
75 int i = 10;
76 char* cp = reinterpret_cast<char*>(&i);
77
78 int* ip;
79 (var(ip) = ll_reinterpret_cast<int *>(cp))();
80 BOOST_CHECK(*ip == 10);
81
82
83 // typeid
84
85 BOOST_CHECK(string(ll_typeid(d)().name()) == string(typeid(d).name()));
86
87
88 // sizeof
89
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));
94
95 int an_array[100];
96 BOOST_CHECK(ll_sizeof(_1)(an_array) == 100 * sizeof(int));
97
98 delete p_derived;
99 delete p_base;
100
101
102 }
103
104 int main() {
105
106 do_test();
107 return boost::report_errors();
108 }