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
11 #include <boost/detail/workaround.hpp>
12
13 #include <boost/range/iterator_range.hpp>
14 #include <boost/range/functions.hpp>
15 #include <boost/range/as_literal.hpp>
16 #include <boost/variant.hpp>
17 #include <boost/mpl/vector.hpp>
18 #include <boost/test/test_tools.hpp>
19 #include <boost/test/unit_test.hpp>
20 #include <string>
21
22 namespace
23 {
24 enum E
25 {
26 e1, e2, e3
27 };
28
test_variant_report()29 void test_variant_report()
30 {
31 typedef boost::mpl::vector<
32 E,
33 std::string,
34 boost::iterator_range<std::string::iterator>
35 >::type args;
36
37 typedef boost::make_variant_over<args>::type variant_t;
38
39 variant_t v;
40 std::string s;
41 v = boost::iterator_range<std::string::iterator>(s.begin(), s.end());
42 v = e2;
43 v = std::string();
44
45 // Rationale:
46 // This is cast to const char* to guard against ambiguity in the case
47 // where std::string::iterator it a char*
48 v = static_cast<const char*>("");
49 }
50 }
51
init_unit_test_suite(int argc,char * argv[])52 boost::unit_test::test_suite* init_unit_test_suite( int argc, char* argv[] )
53 {
54 boost::unit_test::test_suite* test =
55 BOOST_TEST_SUITE("iterator range and variant interoperability");
56
57 test->add(BOOST_TEST_CASE(&test_variant_report));
58
59 return test;
60 }
61