• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*=============================================================================
2     Copyright (c) 2001-2011 Joel de Guzman
3     Copyright (c) 2006 Dan Marsden
4 
5     Distributed under the Boost Software License, Version 1.0. (See accompanying
6     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 ==============================================================================*/
8 #include <boost/detail/lightweight_test.hpp>
9 #include <boost/fusion/support/category_of.hpp>
10 #include <boost/fusion/view/zip_view.hpp>
11 #include <boost/fusion/container/vector.hpp>
12 #include <boost/fusion/container/list.hpp>
13 #include <boost/fusion/sequence/intrinsic/size.hpp>
14 #include <boost/fusion/sequence/intrinsic/at.hpp>
15 #include <boost/fusion/sequence/intrinsic/front.hpp>
16 #include <boost/fusion/sequence/intrinsic/back.hpp>
17 #include <boost/fusion/iterator/next.hpp>
18 #include <boost/fusion/iterator/prior.hpp>
19 #include <boost/fusion/iterator/deref.hpp>
20 #include <boost/fusion/iterator/advance.hpp>
21 #include <boost/fusion/sequence/comparison/equal_to.hpp>
22 #include <boost/fusion/container/generation/make_vector.hpp>
23 #include <boost/fusion/adapted/mpl.hpp>
24 #include <boost/mpl/assert.hpp>
25 #include <boost/mpl/equal_to.hpp>
26 #include <boost/mpl/vector_c.hpp>
27 
28 #include <boost/type_traits/is_reference.hpp>
29 #include <boost/type_traits/is_same.hpp>
30 #include <boost/static_assert.hpp>
31 
main()32 int main()
33 {
34     using namespace boost::fusion;
35     {
36         typedef vector2<int,int> int_vector;
37         typedef vector2<char,char> char_vector;
38         typedef vector<int_vector&, char_vector&> seqs_type;
39         typedef zip_view<seqs_type> view;
40 
41         BOOST_MPL_ASSERT((boost::mpl::equal_to<boost::fusion::result_of::size<view>::type, boost::fusion::result_of::size<int_vector>::type>));
42         BOOST_STATIC_ASSERT((boost::fusion::result_of::size<view>::value == 2));
43 
44         int_vector iv(1,2);
45         char_vector cv('a', 'b');
46         seqs_type seqs(iv, cv);
47         view v(seqs);
48 
49         BOOST_TEST(at_c<0>(v) == make_vector(1, 'a'));
50         BOOST_TEST(at_c<1>(v) == make_vector(2, 'b'));
51         BOOST_TEST(front(v) == make_vector(1, 'a'));
52         BOOST_TEST(back(v) == make_vector(2, 'b'));
53         BOOST_TEST(*next(begin(v)) == make_vector(2, 'b'));
54         BOOST_TEST(*prior(end(v)) == make_vector(2, 'b'));
55         BOOST_TEST(advance_c<2>(begin(v)) == end(v));
56         BOOST_TEST(advance_c<-2>(end(v)) == begin(v));
57         BOOST_TEST(distance(begin(v), end(v)) == 2);
58 
59         BOOST_STATIC_ASSERT((boost::fusion::result_of::distance<boost::fusion::result_of::begin<view>::type, boost::fusion::result_of::end<view>::type>::value == 2));
60 
61         BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::value_at_c<view,0>::type, vector2<int,char> >));
62         BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::value_of<boost::fusion::result_of::begin<view>::type>::type, vector2<int,char> >));
63     }
64     {
65         using namespace boost;
66         typedef mpl::vector2<int,bool> v1_type;
67         typedef mpl::vector2<char,long> v2_type;
68         typedef fusion::vector<v1_type&, v2_type&> seqs_type;
69         typedef fusion::zip_view<seqs_type> view;
70 
71         v1_type v1;
72         v2_type v2;
73         seqs_type seqs(v1,v2);
74         view v(seqs);
75         BOOST_TEST((fusion::at_c<0>(v) == mpl::vector2<int,char>()));
76         BOOST_TEST((fusion::at_c<1>(v) == mpl::vector2<bool,long>()));
77         BOOST_TEST((fusion::front(v) == mpl::vector2<int,char>()));
78         BOOST_TEST((fusion::back(v) == mpl::vector2<bool,long>()));
79         BOOST_TEST((*fusion::next(fusion::begin(v)) == mpl::vector2<bool,long>()));
80         BOOST_TEST((*fusion::prior(fusion::end(v)) == mpl::vector2<bool,long>()));
81         BOOST_TEST(fusion::advance_c<2>(fusion::begin(v)) == fusion::end(v));
82         BOOST_TEST(fusion::advance_c<-2>(fusion::end(v)) == fusion::begin(v));
83         BOOST_TEST(fusion::distance(fusion::begin(v), fusion::end(v)) == 2);
84     }
85     return boost::report_errors();
86 }
87 
88