variant_rvalue_get_with_ampersand_test.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. //-----------------------------------------------------------------------------
  2. // boost-libs variant/test/variant_get_test.cpp source file
  3. // See http://www.boost.org for updates, documentation, and revision history.
  4. //-----------------------------------------------------------------------------
  5. //
  6. // Copyright (c) 2017-2017 Albert Sverdlov
  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. #include "boost/variant/get.hpp"
  12. #include "boost/variant/variant.hpp"
  13. #include "boost/core/lightweight_test.hpp"
  14. #include <boost/move/move.hpp>
  15. #include <boost/static_assert.hpp>
  16. #include <string>
  17. #define UNUSED(v) (void)(v)
  18. inline void run()
  19. {
  20. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  21. typedef boost::variant<int, std::string> var_t;
  22. std::string s = "abacaba";
  23. var_t v = s;
  24. // must spit an error at compile-time because of 'std::string&'
  25. std::string new_s = boost::strict_get<std::string&>(boost::move(v));
  26. UNUSED(new_s);
  27. #else
  28. BOOST_STATIC_ASSERT_MSG(false, "Dummy compile-time error to pass the test on C++03");
  29. #endif
  30. }
  31. int main()
  32. {
  33. run();
  34. return boost::report_errors();
  35. }