iterator_range_variant.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Boost.Range library
  2. //
  3. // Copyright Neil Groves 2014. Use, modification and
  4. // distribution is subject to the Boost Software License, Version
  5. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. // For more information, see http://www.boost.org/libs/range/
  9. //
  10. #include <boost/detail/workaround.hpp>
  11. #include <boost/range/iterator_range.hpp>
  12. #include <boost/range/functions.hpp>
  13. #include <boost/range/as_literal.hpp>
  14. #include <boost/variant.hpp>
  15. #include <boost/mpl/vector.hpp>
  16. #include <boost/test/test_tools.hpp>
  17. #include <boost/test/unit_test.hpp>
  18. #include <string>
  19. namespace
  20. {
  21. enum E
  22. {
  23. e1, e2, e3
  24. };
  25. void test_variant_report()
  26. {
  27. typedef boost::mpl::vector<
  28. E,
  29. std::string,
  30. boost::iterator_range<std::string::iterator>
  31. >::type args;
  32. typedef boost::make_variant_over<args>::type variant_t;
  33. variant_t v;
  34. std::string s;
  35. v = boost::iterator_range<std::string::iterator>(s.begin(), s.end());
  36. v = e2;
  37. v = std::string();
  38. // Rationale:
  39. // This is cast to const char* to guard against ambiguity in the case
  40. // where std::string::iterator it a char*
  41. v = static_cast<const char*>("");
  42. }
  43. }
  44. boost::unit_test::test_suite* init_unit_test_suite( int argc, char* argv[] )
  45. {
  46. boost::unit_test::test_suite* test =
  47. BOOST_TEST_SUITE("iterator range and variant interoperability");
  48. test->add(BOOST_TEST_CASE(&test_variant_report));
  49. return test;
  50. }