test4.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. //-----------------------------------------------------------------------------
  2. // boost-libs variant/test/test4.cpp source file
  3. // See http://www.boost.org for updates, documentation, and revision history.
  4. //-----------------------------------------------------------------------------
  5. //
  6. // Copyright (c) 2003
  7. // Eric Friedman, Itay Maman
  8. //
  9. // Distributed under the Boost Software License, Version 1.0. (See
  10. // accompanying file LICENSE_1_0.txt or copy at
  11. // http://www.boost.org/LICENSE_1_0.txt)
  12. #include "boost/config.hpp"
  13. #ifdef BOOST_MSVC
  14. #pragma warning(disable:4244) // conversion from 'const int' to 'const short'
  15. #endif
  16. #include "boost/core/lightweight_test.hpp"
  17. #include "boost/variant.hpp"
  18. #include "jobs.h"
  19. #include <string>
  20. struct class_a;
  21. using boost::variant;
  22. typedef variant<std::string, class_a, float> var_type_1;
  23. typedef variant<std::string, class_a, short> var_type_2;
  24. #include "class_a.h"
  25. int main()
  26. {
  27. using namespace boost;
  28. var_type_1 v1;
  29. var_type_2 v2;
  30. v1 = class_a();
  31. verify(v1, spec<class_a>(), "[V] class_a(5511)");
  32. verify(v2, spec<std::string>(), "[V] ");
  33. v2 = "abcde";
  34. verify(v2, spec<std::string>(), "[V] abcde");
  35. v2 = v1;
  36. verify(v2, spec<class_a>(), "[V] class_a(5511)");
  37. v2 = 5;
  38. v1 = v2;
  39. return boost::report_errors();
  40. }