Chris@16
|
1 /*=============================================================================
|
Chris@16
|
2 Copyright (c) 2009 Christopher Schmidt
|
Chris@16
|
3
|
Chris@16
|
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6 ==============================================================================*/
|
Chris@16
|
7
|
Chris@16
|
8 #ifndef BOOST_FUSION_ITERATOR_BASIC_ITERATOR_HPP
|
Chris@16
|
9 #define BOOST_FUSION_ITERATOR_BASIC_ITERATOR_HPP
|
Chris@16
|
10
|
Chris@101
|
11 #include <boost/fusion/support/config.hpp>
|
Chris@16
|
12 #include <boost/fusion/iterator/iterator_facade.hpp>
|
Chris@16
|
13
|
Chris@16
|
14 #include <boost/mpl/and.hpp>
|
Chris@16
|
15 #include <boost/mpl/equal_to.hpp>
|
Chris@16
|
16 #include <boost/mpl/minus.hpp>
|
Chris@16
|
17 #include <boost/mpl/int.hpp>
|
Chris@16
|
18 #include <boost/type_traits/is_same.hpp>
|
Chris@16
|
19 #include <boost/type_traits/remove_const.hpp>
|
Chris@16
|
20
|
Chris@16
|
21 namespace boost { namespace fusion
|
Chris@16
|
22 {
|
Chris@16
|
23 namespace extension
|
Chris@16
|
24 {
|
Chris@16
|
25 template <typename>
|
Chris@16
|
26 struct value_of_impl;
|
Chris@16
|
27
|
Chris@16
|
28 template <typename>
|
Chris@16
|
29 struct deref_impl;
|
Chris@16
|
30
|
Chris@16
|
31 template <typename>
|
Chris@16
|
32 struct value_of_data_impl;
|
Chris@16
|
33
|
Chris@16
|
34 template <typename>
|
Chris@16
|
35 struct key_of_impl;
|
Chris@16
|
36
|
Chris@16
|
37 template <typename>
|
Chris@16
|
38 struct deref_data_impl;
|
Chris@16
|
39 }
|
Chris@16
|
40
|
Chris@16
|
41 template<typename Tag, typename Category, typename Seq, int Index>
|
Chris@16
|
42 struct basic_iterator
|
Chris@101
|
43 : iterator_facade<basic_iterator<Tag, Category, Seq, Index>, Category>
|
Chris@16
|
44 {
|
Chris@16
|
45 typedef mpl::int_<Index> index;
|
Chris@16
|
46 typedef Seq seq_type;
|
Chris@16
|
47
|
Chris@16
|
48 template <typename It>
|
Chris@16
|
49 struct value_of
|
Chris@16
|
50 : extension::value_of_impl<Tag>::template apply<It>
|
Chris@16
|
51 {};
|
Chris@16
|
52
|
Chris@16
|
53 template <typename It>
|
Chris@16
|
54 struct deref
|
Chris@16
|
55 : extension::deref_impl<Tag>::template apply<It>
|
Chris@16
|
56 {};
|
Chris@16
|
57
|
Chris@16
|
58 template <typename It>
|
Chris@16
|
59 struct value_of_data
|
Chris@16
|
60 : extension::value_of_data_impl<Tag>::template apply<It>
|
Chris@16
|
61 {};
|
Chris@16
|
62
|
Chris@16
|
63 template <typename It>
|
Chris@16
|
64 struct key_of
|
Chris@16
|
65 : extension::key_of_impl<Tag>::template apply<It>
|
Chris@16
|
66 {};
|
Chris@16
|
67
|
Chris@16
|
68 template <typename It>
|
Chris@16
|
69 struct deref_data
|
Chris@16
|
70 : extension::deref_data_impl<Tag>::template apply<It>
|
Chris@16
|
71 {};
|
Chris@16
|
72
|
Chris@16
|
73 template <typename It, typename N>
|
Chris@16
|
74 struct advance
|
Chris@16
|
75 {
|
Chris@16
|
76 typedef
|
Chris@16
|
77 basic_iterator<Tag, Category, Seq, Index + N::value>
|
Chris@16
|
78 type;
|
Chris@16
|
79
|
Chris@101
|
80 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
81 static type
|
Chris@16
|
82 call(It const& it)
|
Chris@16
|
83 {
|
Chris@16
|
84 return type(*it.seq,0);
|
Chris@16
|
85 }
|
Chris@16
|
86 };
|
Chris@16
|
87
|
Chris@16
|
88 template <typename It>
|
Chris@16
|
89 struct next
|
Chris@16
|
90 : advance<It, mpl::int_<1> >
|
Chris@16
|
91 {};
|
Chris@16
|
92
|
Chris@16
|
93 template <typename It>
|
Chris@16
|
94 struct prior
|
Chris@16
|
95 : advance<It, mpl::int_<-1> >
|
Chris@16
|
96 {};
|
Chris@16
|
97
|
Chris@16
|
98 template <typename It1, typename It2>
|
Chris@16
|
99 struct distance
|
Chris@16
|
100 {
|
Chris@16
|
101 typedef mpl::minus<typename It2::index, typename It1::index> type;
|
Chris@16
|
102
|
Chris@101
|
103 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
104 static
|
Chris@16
|
105 type
|
Chris@16
|
106 call(It1 const&, It2 const&)
|
Chris@16
|
107 {
|
Chris@16
|
108 return type();
|
Chris@16
|
109 }
|
Chris@16
|
110 };
|
Chris@16
|
111
|
Chris@16
|
112 template <typename It1, typename It2>
|
Chris@16
|
113 struct equal_to
|
Chris@16
|
114 : mpl::and_<
|
Chris@16
|
115 is_same<
|
Chris@16
|
116 typename remove_const<typename It1::seq_type>::type
|
Chris@16
|
117 , typename remove_const<typename It2::seq_type>::type
|
Chris@16
|
118 >
|
Chris@16
|
119 , mpl::equal_to<typename It1::index,typename It2::index>
|
Chris@16
|
120 >
|
Chris@16
|
121 {};
|
Chris@16
|
122
|
Chris@16
|
123 template<typename OtherSeq>
|
Chris@101
|
124 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
125 basic_iterator(basic_iterator<Tag,Category,OtherSeq,Index> const& it)
|
Chris@16
|
126 : seq(it.seq)
|
Chris@16
|
127 {}
|
Chris@16
|
128
|
Chris@101
|
129 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
130 basic_iterator(Seq& in_seq, int)
|
Chris@16
|
131 : seq(&in_seq)
|
Chris@16
|
132 {}
|
Chris@16
|
133
|
Chris@16
|
134 template<typename OtherSeq>
|
Chris@101
|
135 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
136 basic_iterator&
|
Chris@16
|
137 operator=(basic_iterator<Tag,Category,OtherSeq,Index> const& it)
|
Chris@16
|
138 {
|
Chris@16
|
139 seq=it.seq;
|
Chris@16
|
140 return *this;
|
Chris@16
|
141 }
|
Chris@16
|
142
|
Chris@16
|
143 Seq* seq;
|
Chris@16
|
144 };
|
Chris@16
|
145 }}
|
Chris@16
|
146
|
Chris@101
|
147 #ifdef BOOST_FUSION_WORKAROUND_FOR_LWG_2408
|
Chris@101
|
148 namespace std
|
Chris@101
|
149 {
|
Chris@101
|
150 template <typename Tag, typename Category, typename Seq, int Index>
|
Chris@101
|
151 struct iterator_traits< ::boost::fusion::basic_iterator<Tag, Category, Seq, Index> >
|
Chris@101
|
152 { };
|
Chris@101
|
153 }
|
Chris@16
|
154 #endif
|
Chris@101
|
155
|
Chris@101
|
156 #endif
|