• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*=============================================================================
2     Copyright (c) 2001-2011 Joel de Guzman
3 
4     Distributed under the Boost Software License, Version 1.0. (See accompanying
5     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 ==============================================================================*/
7 #include <boost/detail/lightweight_test.hpp>
8 #include <boost/fusion/container/vector/vector.hpp>
9 #include <boost/fusion/adapted/mpl.hpp>
10 #include <boost/fusion/sequence/io/out.hpp>
11 #include <boost/fusion/sequence/comparison/equal_to.hpp>
12 #include <boost/fusion/container/generation/make_vector.hpp>
13 #include <boost/fusion/algorithm/transformation/insert_range.hpp>
14 #include <boost/mpl/vector_c.hpp>
15 #include <boost/mpl/begin_end.hpp>
16 #include <boost/mpl/advance.hpp>
17 #include <boost/mpl/int.hpp>
18 #include <string>
19 
20 int
main()21 main()
22 {
23     using namespace boost::fusion;
24     using boost::mpl::vector_c;
25     using boost::mpl::advance;
26     using boost::mpl::int_;
27     namespace fusion = boost::fusion;
28     namespace mpl = boost::mpl;
29 
30     std::cout << tuple_open('[');
31     std::cout << tuple_close(']');
32     std::cout << tuple_delimiter(", ");
33 
34 /// Testing insert_range
35 
36     {
37         char const* s = "Ruby";
38         typedef vector<int, char, double, char const*> vector_type;
39         vector_type t1(1, 'x', 3.3, s);
40         vector_iterator<vector_type, 2> pos(t1);
41 
42         typedef vector<int, char> vector_type2;
43         vector_type2 t2(999, 'z');
44 
45         std::cout << insert_range(t1, pos, t2) << std::endl;
46         BOOST_TEST((insert_range(t1, pos, t2)
47             == make_vector(1, 'x', 999, 'z', 3.3, s)));
48 
49         std::cout << insert_range(t1, end(t1), t2) << std::endl;
50         BOOST_TEST((insert_range(t1, end(t1), t2)
51             == make_vector(1, 'x', 3.3, s, 999, 'z')));
52 
53         std::cout << insert_range(t1, begin(t1), t2) << std::endl;
54         BOOST_TEST((insert_range(t1, begin(t1), t2)
55             == make_vector(999, 'z', 1, 'x', 3.3, s)));
56     }
57 
58     {
59         typedef vector_c<int, 1, 2, 3, 4, 5> mpl_vec;
60         typedef mpl::begin<mpl_vec>::type mpl_vec_begin;
61         typedef advance<mpl_vec_begin, int_<3> >::type mpl_vec_at3;
62         typedef vector_c<int, -1, -2> mpl_vec2;
63 
64         std::cout << fusion::insert_range(mpl_vec(), mpl_vec_at3(), mpl_vec2()) << std::endl;
65         BOOST_TEST((fusion::insert_range(mpl_vec(), mpl_vec_at3(), mpl_vec2())
66             == make_vector(1, 2, 3, -1, -2, 4, 5)));
67     }
68 
69     return boost::report_errors();
70 }
71 
72