issue53.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //-----------------------------------------------------------------------------
  2. // boost-libs variant/test/issue53.cpp source file
  3. // See http://www.boost.org for updates, documentation, and revision history.
  4. //-----------------------------------------------------------------------------
  5. //
  6. // Copyright (c) 2019 Antony Polukhin
  7. //
  8. // Distributed under the Boost Software License, Version 1.0. (See
  9. // accompanying file LICENSE_1_0.txt or copy at
  10. // http://www.boost.org/LICENSE_1_0.txt)
  11. // Test case from https://github.com/boostorg/variant/issues/53
  12. #include <boost/variant.hpp>
  13. #include <boost/thread/lock_guard.hpp> // this line was causing problems on MSVC
  14. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  15. struct spanac {};
  16. struct ceapa{
  17. double a,b;
  18. };
  19. typedef boost::variant<spanac, ceapa> var_t;
  20. struct visitor_t : public boost::static_visitor<bool> {
  21. bool operator() (const spanac&) const {
  22. return true;
  23. }
  24. bool operator() (const ceapa&) const {
  25. return false;
  26. }
  27. private:
  28. double a, b;
  29. };
  30. var_t get(int k) {
  31. if (k)
  32. return spanac();
  33. else
  34. return ceapa();
  35. }
  36. int main(int argc, const char** argv) {
  37. visitor_t v;
  38. bool result = boost::apply_visitor(v, get(argc - 1));
  39. (void)result;
  40. }
  41. #else // #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  42. int main() {}
  43. #endif // #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES