1 |
|
---|
2 | #include <boost\type_traits\is_same.hpp>
|
---|
3 | #include <boost\variant\detail\apply_visitor_binary.hpp>
|
---|
4 | #include <boost\variant\static_visitor.hpp>
|
---|
5 | #include <boost\variant\variant.hpp>
|
---|
6 | #include <boost\smart_ptr\shared_ptr.hpp>
|
---|
7 |
|
---|
8 | #define WANT_BUILD_TO_FAIL
|
---|
9 | #ifdef WANT_BUILD_TO_FAIL
|
---|
10 | #include <boost\thread.hpp>
|
---|
11 | #endif
|
---|
12 |
|
---|
13 |
|
---|
14 |
|
---|
15 | class AType
|
---|
16 | {
|
---|
17 |
|
---|
18 | };
|
---|
19 |
|
---|
20 | class BType
|
---|
21 | {
|
---|
22 | };
|
---|
23 |
|
---|
24 | typedef boost::shared_ptr<AType> IATypePtr;
|
---|
25 | typedef boost::shared_ptr<BType> IBTypePtr;
|
---|
26 |
|
---|
27 | typedef boost::variant<IATypePtr, IBTypePtr> ABVar;
|
---|
28 |
|
---|
29 | struct ServiceTimeTableEvent
|
---|
30 | {
|
---|
31 | public:
|
---|
32 |
|
---|
33 | ServiceTimeTableEvent(ABVar abType)
|
---|
34 | : m_abType{ abType }
|
---|
35 | {}
|
---|
36 |
|
---|
37 | inline ABVar GetABType() const { return m_abType; }
|
---|
38 |
|
---|
39 | private:
|
---|
40 | ABVar m_abType;
|
---|
41 | };
|
---|
42 |
|
---|
43 | class ab_are_equals
|
---|
44 | : public boost::static_visitor<bool>
|
---|
45 | {
|
---|
46 | public:
|
---|
47 | template<typename T, typename U>
|
---|
48 | bool operator()(T, U) const
|
---|
49 | {
|
---|
50 | return false; // cannot compare different types
|
---|
51 | }
|
---|
52 | template<typename T>
|
---|
53 | bool operator()(T lhs, T rhs) const
|
---|
54 | {
|
---|
55 | return lhs == rhs;
|
---|
56 | }
|
---|
57 | };
|
---|
58 |
|
---|
59 | int main(int argc, char* argv[])
|
---|
60 | {
|
---|
61 |
|
---|
62 | auto aTypePtr = IATypePtr{ new AType };
|
---|
63 | auto bTypePtr = IBTypePtr{ new BType };
|
---|
64 |
|
---|
65 | ABVar aType = aTypePtr;
|
---|
66 | ABVar bType = bTypePtr;
|
---|
67 |
|
---|
68 | ServiceTimeTableEvent timeTableEvent1{ aType };
|
---|
69 | ServiceTimeTableEvent timeTableEvent2{ bType };
|
---|
70 |
|
---|
71 | auto xx = boost::apply_visitor(ab_are_equals(), timeTableEvent1.GetABType(), timeTableEvent2.GetABType());
|
---|
72 | xx = boost::apply_visitor(ab_are_equals(), timeTableEvent1.GetABType(), timeTableEvent1.GetABType());;
|
---|
73 | xx = boost::apply_visitor(ab_are_equals(), timeTableEvent2.GetABType(), timeTableEvent2.GetABType());;
|
---|
74 | }
|
---|
75 |
|
---|
76 |
|
---|