File: zip_view.cpp

package info (click to toggle)
boost1.74 1.74.0-9
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 464,084 kB
  • sloc: cpp: 3,338,324; xml: 131,293; python: 33,088; ansic: 14,336; asm: 4,034; sh: 3,351; makefile: 1,193; perl: 1,036; yacc: 478; php: 212; ruby: 102; lisp: 24; sql: 13; csh: 6
file content (87 lines) | stat: -rw-r--r-- 3,974 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*=============================================================================
    Copyright (c) 2001-2011 Joel de Guzman
    Copyright (c) 2006 Dan Marsden

    Distributed under the Boost Software License, Version 1.0. (See accompanying
    file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/support/category_of.hpp>
#include <boost/fusion/view/zip_view.hpp>
#include <boost/fusion/container/vector.hpp>
#include <boost/fusion/container/list.hpp>
#include <boost/fusion/sequence/intrinsic/size.hpp>
#include <boost/fusion/sequence/intrinsic/at.hpp>
#include <boost/fusion/sequence/intrinsic/front.hpp>
#include <boost/fusion/sequence/intrinsic/back.hpp>
#include <boost/fusion/iterator/next.hpp>
#include <boost/fusion/iterator/prior.hpp>
#include <boost/fusion/iterator/deref.hpp>
#include <boost/fusion/iterator/advance.hpp>
#include <boost/fusion/sequence/comparison/equal_to.hpp>
#include <boost/fusion/container/generation/make_vector.hpp>
#include <boost/fusion/adapted/mpl.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/mpl/equal_to.hpp>
#include <boost/mpl/vector_c.hpp>

#include <boost/type_traits/is_reference.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/static_assert.hpp>

int main()
{
    using namespace boost::fusion;
    {
        typedef vector2<int,int> int_vector;
        typedef vector2<char,char> char_vector;
        typedef vector<int_vector&, char_vector&> seqs_type;
        typedef zip_view<seqs_type> view;

        BOOST_MPL_ASSERT((boost::mpl::equal_to<boost::fusion::result_of::size<view>::type, boost::fusion::result_of::size<int_vector>::type>));
        BOOST_STATIC_ASSERT((boost::fusion::result_of::size<view>::value == 2));

        int_vector iv(1,2);
        char_vector cv('a', 'b');
        seqs_type seqs(iv, cv);
        view v(seqs);

        BOOST_TEST(at_c<0>(v) == make_vector(1, 'a'));
        BOOST_TEST(at_c<1>(v) == make_vector(2, 'b'));
        BOOST_TEST(front(v) == make_vector(1, 'a'));
        BOOST_TEST(back(v) == make_vector(2, 'b'));
        BOOST_TEST(*next(begin(v)) == make_vector(2, 'b'));
        BOOST_TEST(*prior(end(v)) == make_vector(2, 'b'));
        BOOST_TEST(advance_c<2>(begin(v)) == end(v));
        BOOST_TEST(advance_c<-2>(end(v)) == begin(v));
        BOOST_TEST(distance(begin(v), end(v)) == 2);

        BOOST_STATIC_ASSERT((boost::fusion::result_of::distance<boost::fusion::result_of::begin<view>::type, boost::fusion::result_of::end<view>::type>::value == 2));

        BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::value_at_c<view,0>::type, vector2<int,char> >));
        BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::value_of<boost::fusion::result_of::begin<view>::type>::type, vector2<int,char> >));
    }
    {
        using namespace boost;
        typedef mpl::vector2<int,bool> v1_type;
        typedef mpl::vector2<char,long> v2_type;
        typedef fusion::vector<v1_type&, v2_type&> seqs_type;
        typedef fusion::zip_view<seqs_type> view;

        v1_type v1;
        v2_type v2;
        seqs_type seqs(v1,v2);
        view v(seqs);
        BOOST_TEST((fusion::at_c<0>(v) == mpl::vector2<int,char>()));
        BOOST_TEST((fusion::at_c<1>(v) == mpl::vector2<bool,long>()));
        BOOST_TEST((fusion::front(v) == mpl::vector2<int,char>()));
        BOOST_TEST((fusion::back(v) == mpl::vector2<bool,long>()));
        BOOST_TEST((*fusion::next(fusion::begin(v)) == mpl::vector2<bool,long>()));
        BOOST_TEST((*fusion::prior(fusion::end(v)) == mpl::vector2<bool,long>()));
        BOOST_TEST(fusion::advance_c<2>(fusion::begin(v)) == fusion::end(v));
        BOOST_TEST(fusion::advance_c<-2>(fusion::end(v)) == fusion::begin(v));
        BOOST_TEST(fusion::distance(fusion::begin(v), fusion::end(v)) == 2);
    }
    return boost::report_errors();
}