test_13480b.cpp 1.8 KB

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