]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/fusion/test/sequence/iterator_range.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / fusion / test / sequence / iterator_range.cpp
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/map.hpp>
9 #include <boost/fusion/container/vector/vector.hpp>
10 #include <boost/fusion/container/generation/make_vector.hpp>
11 #include <boost/fusion/view/iterator_range/iterator_range.hpp>
12 #include <boost/fusion/sequence/comparison/equal_to.hpp>
13 #include <boost/fusion/sequence/io/out.hpp>
14 #include <boost/fusion/sequence/intrinsic/size.hpp>
15 #include <boost/fusion/sequence/intrinsic/begin.hpp>
16 #include <boost/fusion/sequence/intrinsic/has_key.hpp>
17 #include <boost/fusion/iterator/advance.hpp>
18 #include <boost/fusion/iterator/key_of.hpp>
19 #include <boost/fusion/iterator/value_of_data.hpp>
20 #include <boost/fusion/iterator/deref_data.hpp>
21 #include <boost/mpl/vector_c.hpp>
22 #include <boost/mpl/begin.hpp>
23 #include <boost/mpl/next.hpp>
24 #include <boost/mpl/assert.hpp>
25 #include <boost/static_assert.hpp>
26
27 int
28 main()
29 {
30 using namespace boost::fusion;
31 namespace fusion = boost::fusion;
32
33 std::cout << tuple_open('[');
34 std::cout << tuple_close(']');
35 std::cout << tuple_delimiter(", ");
36
37 {
38 char const* s = "Ruby";
39 typedef vector<int, char, double, char const*> vector_type;
40 vector_type vec(1, 'x', 3.3, s);
41
42 {
43 typedef vector_iterator<vector_type, 1> i1t;
44 typedef vector_iterator<vector_type, 3> i3t;
45
46 i1t i1(vec);
47 i3t i3(vec);
48
49 typedef iterator_range<i1t, i3t> slice_t;
50 slice_t slice(i1, i3);
51 std::cout << slice << std::endl;
52 BOOST_TEST((slice == make_vector('x', 3.3)));
53 BOOST_STATIC_ASSERT(boost::fusion::result_of::size<slice_t>::value == 2);
54 }
55
56 {
57 typedef vector_iterator<vector_type, 0> i1t;
58 typedef vector_iterator<vector_type, 0> i3t;
59
60 i1t i1(vec);
61 i3t i3(vec);
62
63 typedef iterator_range<i1t, i3t> slice_t;
64 slice_t slice(i1, i3);
65 std::cout << slice << std::endl;
66 BOOST_TEST(slice == make_vector());
67 BOOST_STATIC_ASSERT(boost::fusion::result_of::size<slice_t>::value == 0);
68 }
69 }
70
71 {
72 typedef boost::mpl::vector_c<int, 2, 3, 4, 5, 6> mpl_vec;
73 typedef boost::mpl::begin<mpl_vec>::type it0;
74 typedef boost::mpl::next<it0>::type it1;
75 typedef boost::mpl::next<it1>::type it2;
76 typedef boost::mpl::next<it2>::type it3;
77
78 it1 f;
79 it3 l;
80
81 typedef iterator_range<it1, it3> slice_t;
82 slice_t slice(f, l);
83 std::cout << slice << std::endl;
84 BOOST_TEST((slice == make_vector(3, 4)));
85 BOOST_STATIC_ASSERT(boost::fusion::result_of::size<slice_t>::value == 2);
86 }
87
88 {
89 typedef map<pair<void,std::string>, pair<double,char>,pair<void*, int> > map_type;
90 map_type m(make_pair<void>("foo"), make_pair<double>('x'), make_pair<void*>(2));
91
92 typedef iterator_range<
93 boost::fusion::result_of::begin<map_type>::type
94 , boost::fusion::result_of::advance_c<boost::fusion::result_of::begin<map_type>::type,2>::type
95 > range_type;
96 range_type r(begin(m), advance_c<2>(begin(m)));
97
98 BOOST_MPL_ASSERT((boost::fusion::result_of::has_key<range_type, void>::type));
99 BOOST_MPL_ASSERT((boost::fusion::result_of::has_key<range_type, double>::type));
100
101 BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::key_of<boost::fusion::result_of::begin<range_type>::type>::type, void>));
102 BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::key_of<boost::fusion::result_of::next<boost::fusion::result_of::begin<range_type>::type>::type>::type, double>));
103
104 BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::value_of_data<boost::fusion::result_of::begin<range_type>::type>::type, std::string>));
105 BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::value_of_data<boost::fusion::result_of::next<boost::fusion::result_of::begin<range_type>::type>::type>::type, char>));
106
107 std::cout << deref_data(begin(r)) << std::endl;
108 std::cout << deref_data(fusion::next(begin(r))) << std::endl;
109 BOOST_TEST((deref_data(begin(r)) == "foo"));
110 BOOST_TEST((deref_data(fusion::next(begin(r))) == 'x'));
111 }
112
113 return boost::report_errors();
114 }
115