1 | // comment if you want to see the boost::move issue |
2 | #define BOOST_THREAD_VERSION 3 |
3 | |
4 | #include <boost/type_traits/is_same.hpp> |
5 | #include <boost/variant/detail/apply_visitor_binary.hpp> |
6 | #include <boost/variant/static_visitor.hpp> |
7 | #include <boost/variant/variant.hpp> |
8 | #include <boost/smart_ptr/shared_ptr.hpp> |
9 | |
10 | #define WANT_BUILD_TO_FAIL |
11 | #ifdef WANT_BUILD_TO_FAIL |
12 | #include <boost/thread.hpp> |
13 | #endif |
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 const& GetABType() const { return m_abType; } |
38 | inline ABVar & GetABType() { return m_abType; } |
39 | |
40 | private: |
41 | ABVar m_abType; |
42 | }; |
43 | |
44 | class ab_are_equals |
45 | : public boost::static_visitor<bool> |
46 | { |
47 | public: |
48 | template<typename T, typename U> |
49 | bool operator()(T, U) const |
50 | { |
51 | return false; // cannot compare different types |
52 | } |
53 | template<typename T> |
54 | bool operator()(T lhs, T rhs) const |
55 | { |
56 | return lhs == rhs; |
57 | } |
58 | }; |
59 | |
60 | int main(int argc, char* argv[]) |
61 | { |
62 | |
63 | auto aTypePtr = IATypePtr{ new AType }; |
64 | auto bTypePtr = IBTypePtr{ new BType }; |
65 | |
66 | ABVar aType = aTypePtr; |
67 | ABVar bType = bTypePtr; |
68 | |
69 | ServiceTimeTableEvent timeTableEvent1{ aType }; |
70 | ServiceTimeTableEvent timeTableEvent2{ bType }; |
71 | |
72 | auto xx = boost::apply_visitor(visitor: ab_are_equals(), visitable1&: timeTableEvent1.GetABType(), visitable2&: timeTableEvent2.GetABType()); |
73 | xx = boost::apply_visitor(visitor: ab_are_equals(), visitable1&: timeTableEvent1.GetABType(), visitable2&: timeTableEvent1.GetABType());; |
74 | xx = boost::apply_visitor(visitor: ab_are_equals(), visitable1&: timeTableEvent2.GetABType(), visitable2&: timeTableEvent2.GetABType());; |
75 | } |
76 | |
77 | |
78 | |