• 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/container/map/map.hpp>
10 #include <boost/fusion/adapted/mpl.hpp>
11 #include <boost/fusion/sequence/io/out.hpp>
12 #include <boost/fusion/container/generation/make_vector.hpp>
13 #include <boost/fusion/sequence/comparison/equal_to.hpp>
14 #include <boost/fusion/view/reverse_view/reverse_view.hpp>
15 #include <boost/fusion/sequence/intrinsic/begin.hpp>
16 #include <boost/fusion/sequence/intrinsic/at.hpp>
17 #include <boost/fusion/sequence/intrinsic/value_at.hpp>
18 #include <boost/fusion/iterator/next.hpp>
19 #include <boost/fusion/iterator/prior.hpp>
20 #include <boost/fusion/iterator/deref.hpp>
21 #include <boost/fusion/iterator/advance.hpp>
22 #include <boost/fusion/iterator/distance.hpp>
23 #include <boost/mpl/assert.hpp>
24 #include <boost/mpl/range_c.hpp>
25 #include <boost/type_traits/is_same.hpp>
26 
27 
28 int
main()29 main()
30 {
31     using namespace boost::fusion;
32 
33     std::cout << tuple_open('[');
34     std::cout << tuple_close(']');
35     std::cout << tuple_delimiter(", ");
36 
37 /// Testing the reverse_view
38 
39     {
40         typedef boost::mpl::range_c<int, 5, 9> mpl_list1;
41         mpl_list1 l;
42         reverse_view<mpl_list1> rev(l);
43 
44         std::cout << rev << std::endl;
45         BOOST_TEST((rev == make_vector(8, 7, 6, 5)));
46     }
47 
48     {
49         char const* s = "Hi Kim";
50         typedef vector<int, char, long, char const*> vector_type;
51         vector_type t(123, 'x', 123456789, s);
52         typedef reverse_view<vector_type> view_type;
53         view_type rev(t);
54 
55         std::cout << rev << std::endl;
56         BOOST_TEST((rev == make_vector(s, 123456789, 'x', 123)));
57 
58         typedef boost::fusion::result_of::begin<view_type>::type first_type;
59         first_type first_it(begin(rev));
60         typedef boost::fusion::result_of::next<first_type>::type second_type;
61         second_type second_it(next(first_it));
62         BOOST_TEST((*second_it == 123456789));
63         BOOST_TEST((*prior(second_it) == s));
64         BOOST_TEST((*advance_c<2>(first_it) == 'x'));
65         BOOST_TEST((distance(first_it, second_it) == 1));
66 
67         BOOST_TEST((at_c<0>(rev)==s));
68         BOOST_TEST((at_c<1>(rev)==123456789));
69         BOOST_TEST((at_c<2>(rev)=='x'));
70         BOOST_TEST((at_c<3>(rev)==123));
71 
72         BOOST_MPL_ASSERT((
73             boost::is_same<boost::fusion::result_of::value_at_c<view_type,0>::type,char const*>
74         ));
75         BOOST_MPL_ASSERT((
76             boost::is_same<boost::fusion::result_of::value_at_c<view_type,1>::type,long>
77         ));
78         BOOST_MPL_ASSERT((
79             boost::is_same<boost::fusion::result_of::value_at_c<view_type,2>::type,char>
80         ));
81         BOOST_MPL_ASSERT((
82             boost::is_same<boost::fusion::result_of::value_at_c<view_type,3>::type,int>
83         ));
84     }
85 
86     //! Map
87     {
88         typedef pair<boost::mpl::int_<0>, std::string> pair0;
89         typedef pair<boost::mpl::int_<1>, std::string> pair1;
90         typedef pair<boost::mpl::int_<2>, std::string> pair2;
91         typedef pair<boost::mpl::int_<3>, std::string> pair3;
92         typedef pair<boost::mpl::int_<4>, std::string> pair4;
93 
94         typedef map< pair0, pair1, pair2, pair3, pair4 > map_type;
95         map_type m( pair0("zero"), pair1("one"), pair2("two"), pair3("three"), pair4("four") );
96         typedef reverse_view<map_type> view_type;
97         view_type rev(m);
98         std::cout << rev << std::endl;
99         BOOST_TEST((rev == make_vector( pair4("four"), pair3("three"), pair2("two"), pair1("one"), pair0("zero"))));
100         BOOST_TEST((at_c<0>(rev) == pair4("four")));
101         BOOST_TEST((at_c<1>(rev) == pair3("three")));
102         BOOST_TEST((at_c<2>(rev) == pair2("two")));
103         BOOST_TEST((at_c<3>(rev) == pair1("one")));
104         BOOST_TEST((at_c<4>(rev) == pair0("zero")));
105     }
106 
107     return boost::report_errors();
108 }
109 
110