| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
#pragma warning(disable: 4312) |
|---|
| 4 |
|
|---|
| 5 |
#include <cbear.berlios.de/cast/polymorphic.hpp> |
|---|
| 6 |
#include <cbear.berlios.de/cast/polymorphic_down.hpp> |
|---|
| 7 |
#include <cbear.berlios.de/cast/static.hpp> |
|---|
| 8 |
#include <cbear.berlios.de/cast/const.hpp> |
|---|
| 9 |
#include <cbear.berlios.de/cast/dynamic.hpp> |
|---|
| 10 |
#include <cbear.berlios.de/cast/reinterpret.hpp> |
|---|
| 11 |
#include <cbear.berlios.de/cast/safe_reinterpret.hpp> |
|---|
| 12 |
#include <cbear.berlios.de/cast/explicit.hpp> |
|---|
| 13 |
#include <cbear.berlios.de/cast/default.hpp> |
|---|
| 14 |
|
|---|
| 15 |
#include <iostream> |
|---|
| 16 |
|
|---|
| 17 |
class MyClass |
|---|
| 18 |
{ |
|---|
| 19 |
public: |
|---|
| 20 |
MyClass() {} |
|---|
| 21 |
explicit MyClass(char) {} |
|---|
| 22 |
}; |
|---|
| 23 |
|
|---|
| 24 |
struct a |
|---|
| 25 |
{ |
|---|
| 26 |
virtual ~a() |
|---|
| 27 |
{ |
|---|
| 28 |
} |
|---|
| 29 |
|
|---|
| 30 |
void f() |
|---|
| 31 |
{ |
|---|
| 32 |
} |
|---|
| 33 |
}; |
|---|
| 34 |
|
|---|
| 35 |
struct d |
|---|
| 36 |
{ |
|---|
| 37 |
virtual ~d() |
|---|
| 38 |
{ |
|---|
| 39 |
} |
|---|
| 40 |
int c; |
|---|
| 41 |
}; |
|---|
| 42 |
|
|---|
| 43 |
struct b : d, a |
|---|
| 44 |
{ |
|---|
| 45 |
void g() |
|---|
| 46 |
{ |
|---|
| 47 |
} |
|---|
| 48 |
}; |
|---|
| 49 |
|
|---|
| 50 |
struct throw_sfinae |
|---|
| 51 |
{ |
|---|
| 52 |
struct sfinae |
|---|
| 53 |
{ |
|---|
| 54 |
}; |
|---|
| 55 |
explicit throw_sfinae(int) |
|---|
| 56 |
{ |
|---|
| 57 |
throw sfinae(); |
|---|
| 58 |
} |
|---|
| 59 |
}; |
|---|
| 60 |
|
|---|
| 61 |
int main() |
|---|
| 62 |
{ |
|---|
| 63 |
namespace cast = cbear_berlios_de::cast; |
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
MyClass my = cast::explicit_::value('5'); |
|---|
| 67 |
|
|---|
| 68 |
MyClass my3 = cast::default_::value(); |
|---|
| 69 |
|
|---|
| 70 |
char m = cast::static_::to<char>::apply(5); |
|---|
| 71 |
m; |
|---|
| 72 |
|
|---|
| 73 |
int const dc = 7; |
|---|
| 74 |
char const &m1 = cast::reinterpret::to<char const &>::apply(dc); |
|---|
| 75 |
m1; |
|---|
| 76 |
int dv = 7; |
|---|
| 77 |
char &m2 = cast::reinterpret::to<char &>::apply(dv); |
|---|
| 78 |
m2; |
|---|
| 79 |
int i1 = cast::static_::value('a'); |
|---|
| 80 |
int const &i2 = i1; |
|---|
| 81 |
int &i3 = cast::const_::ref(i2); |
|---|
| 82 |
i3 = 2; |
|---|
| 83 |
b bx; |
|---|
| 84 |
a& ax = cast::static_::ref(bx); |
|---|
| 85 |
b * pbx = &bx; |
|---|
| 86 |
a *pax = cast::static_::value(pbx); |
|---|
| 87 |
pax; |
|---|
| 88 |
b& by = cast::dynamic::ref(ax); |
|---|
| 89 |
by; |
|---|
| 90 |
a *pax1 = 0; |
|---|
| 91 |
b *by1 = cast::dynamic::value(pax1); |
|---|
| 92 |
by1; |
|---|
| 93 |
b *by2 = cast::polymorphic::value(&ax); |
|---|
| 94 |
b &by2r = cast::polymorphic::ref(ax); |
|---|
| 95 |
a *ax2 = cast::polymorphic_down::value(by2); |
|---|
| 96 |
a &ax2r = cast::polymorphic_down::ref(by2r); |
|---|
| 97 |
ax2; |
|---|
| 98 |
int* p = cast::safe_reinterpret::value(i1); |
|---|
| 99 |
p; |
|---|
| 100 |
int* p1 = cast::reinterpret::value(i1); |
|---|
| 101 |
try |
|---|
| 102 |
{ |
|---|
| 103 |
d dd; |
|---|
| 104 |
throw_sfinae &ts = cast::dynamic::ref(dd); |
|---|
| 105 |
} |
|---|
| 106 |
catch(...) |
|---|
| 107 |
{ |
|---|
| 108 |
::std::cout << "Good" << ::std::endl; |
|---|
| 109 |
} |
|---|
| 110 |
} |
|---|