]> git.donarmstrong.com Git - rsem.git/blob - boost/fusion/iterator/basic_iterator.hpp
RSEM Source Codes
[rsem.git] / boost / fusion / iterator / basic_iterator.hpp
1 /*=============================================================================
2     Copyright (c) 2009 Christopher Schmidt
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
8 #ifndef BOOST_FUSION_ITERATOR_BASIC_ITERATOR_HPP
9 #define BOOST_FUSION_ITERATOR_BASIC_ITERATOR_HPP
10
11 #include <boost/fusion/iterator/iterator_facade.hpp>
12
13 #include <boost/mpl/and.hpp>
14 #include <boost/mpl/equal_to.hpp>
15 #include <boost/mpl/minus.hpp>
16 #include <boost/mpl/int.hpp>
17 #include <boost/type_traits/is_same.hpp>
18 #include <boost/type_traits/remove_const.hpp>
19
20 namespace boost { namespace fusion
21 {
22     namespace extension
23     {
24         template <typename>
25         struct value_of_impl;
26
27         template <typename>
28         struct deref_impl;
29
30         template <typename>
31         struct value_of_data_impl;
32
33         template <typename>
34         struct key_of_impl;
35
36         template <typename>
37         struct deref_data_impl;
38     }
39
40     template<typename Tag, typename Category, typename Seq, int Index>
41     struct basic_iterator
42       : iterator_facade<basic_iterator<Tag,Category,Seq,Index>, Category>
43     {
44         typedef mpl::int_<Index> index;
45         typedef Seq seq_type;
46
47         template <typename It>
48         struct value_of
49           : extension::value_of_impl<Tag>::template apply<It>
50         {};
51
52         template <typename It>
53         struct deref
54           : extension::deref_impl<Tag>::template apply<It>
55         {};
56
57         template <typename It>
58         struct value_of_data
59           : extension::value_of_data_impl<Tag>::template apply<It>
60         {};
61
62         template <typename It>
63         struct key_of
64           : extension::key_of_impl<Tag>::template apply<It>
65         {};
66
67         template <typename It>
68         struct deref_data
69           : extension::deref_data_impl<Tag>::template apply<It>
70         {};
71
72         template <typename It, typename N>
73         struct advance
74         {
75             typedef
76                 basic_iterator<Tag, Category, Seq, Index + N::value>
77             type;
78
79             static type
80             call(It const& it)
81             {
82                 return type(*it.seq,0);
83             }
84         };
85
86         template <typename It>
87         struct next
88           : advance<It, mpl::int_<1> >
89         {};
90
91         template <typename It>
92         struct prior
93           : advance<It, mpl::int_<-1> >
94         {};
95
96         template <typename It1, typename It2>
97         struct distance
98         {
99             typedef mpl::minus<typename It2::index, typename It1::index> type;
100
101             static
102             type
103             call(It1 const&, It2 const&)
104             {
105                 return type();
106             }
107         };
108
109         template <typename It1, typename It2>
110         struct equal_to
111           : mpl::and_<
112                 is_same<
113                     typename remove_const<typename It1::seq_type>::type
114                   , typename remove_const<typename It2::seq_type>::type
115                 >
116               , mpl::equal_to<typename It1::index,typename It2::index>
117             >
118         {};
119
120         template<typename OtherSeq>
121         basic_iterator(basic_iterator<Tag,Category,OtherSeq,Index> const& it)
122           : seq(it.seq)
123         {}
124
125         basic_iterator(Seq& in_seq, int)
126           : seq(&in_seq)
127         {}
128
129         template<typename OtherSeq>
130         basic_iterator&
131         operator=(basic_iterator<Tag,Category,OtherSeq,Index> const& it)
132         {
133             seq=it.seq;
134             return *this;
135         }
136
137         Seq* seq;
138     };
139 }}
140
141 #endif