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 | #if !defined(FUSION_ITERATOR_ADAPTER_08112011_0942) |
8 | #define FUSION_ITERATOR_ADAPTER_08112011_0942 |
9 | |
10 | #include <boost/fusion/support/config.hpp> |
11 | #include <boost/fusion/support/category_of.hpp> |
12 | #include <boost/fusion/iterator/advance.hpp> |
13 | #include <boost/fusion/iterator/deref.hpp> |
14 | #include <boost/fusion/iterator/distance.hpp> |
15 | #include <boost/fusion/iterator/equal_to.hpp> |
16 | #include <boost/fusion/iterator/iterator_facade.hpp> |
17 | #include <boost/fusion/iterator/next.hpp> |
18 | #include <boost/fusion/iterator/prior.hpp> |
19 | #include <boost/fusion/iterator/value_of.hpp> |
20 | #include <boost/type_traits/remove_const.hpp> |
21 | |
22 | namespace boost { namespace fusion |
23 | { |
24 | template <typename Derived_, typename Iterator_, |
25 | typename Category = typename traits::category_of<Iterator_>::type> |
26 | struct iterator_adapter |
27 | : iterator_facade<Derived_, Category> |
28 | { |
29 | typedef typename |
30 | remove_const<Iterator_>::type |
31 | iterator_base_type; |
32 | iterator_base_type iterator_base; |
33 | |
34 | BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED |
35 | iterator_adapter(iterator_base_type const& iterator_base_) |
36 | : iterator_base(iterator_base_) {} |
37 | |
38 | // default implementation |
39 | template <typename I1, typename I2> |
40 | struct equal_to |
41 | : result_of::equal_to< |
42 | typename I1::iterator_base_type |
43 | , typename I2::iterator_base_type |
44 | > |
45 | {}; |
46 | |
47 | // default implementation |
48 | template <typename Iterator, typename N> |
49 | struct advance |
50 | { |
51 | typedef typename Derived_::template make< |
52 | typename result_of::advance< |
53 | typename Iterator::iterator_base_type, N |
54 | >::type>::type |
55 | type; |
56 | |
57 | BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED |
58 | static type |
59 | call(Iterator const& it) |
60 | { |
61 | return type(fusion::advance<N>(it.iterator_base)); |
62 | } |
63 | }; |
64 | |
65 | // default implementation |
66 | template <typename First, typename Last> |
67 | struct distance |
68 | : result_of::distance< |
69 | typename First::iterator_base_type |
70 | , typename Last::iterator_base_type |
71 | > |
72 | {}; |
73 | |
74 | // default implementation |
75 | template <typename Iterator> |
76 | struct value_of |
77 | : result_of::value_of< |
78 | typename Iterator::iterator_base_type |
79 | > |
80 | {}; |
81 | |
82 | // default implementation |
83 | template <typename Iterator> |
84 | struct deref |
85 | { |
86 | typedef typename |
87 | result_of::deref< |
88 | typename Iterator::iterator_base_type |
89 | >::type |
90 | type; |
91 | |
92 | BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED |
93 | static type |
94 | call(Iterator const& it) |
95 | { |
96 | return fusion::deref(it.iterator_base); |
97 | } |
98 | }; |
99 | |
100 | // default implementation |
101 | template <typename Iterator> |
102 | struct next |
103 | { |
104 | typedef typename Derived_::template make< |
105 | typename result_of::next< |
106 | typename Iterator::iterator_base_type |
107 | >::type>::type |
108 | type; |
109 | |
110 | BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED |
111 | static type |
112 | call(Iterator const& i) |
113 | { |
114 | return type(fusion::next(i.iterator_base)); |
115 | } |
116 | }; |
117 | |
118 | // default implementation |
119 | template <typename Iterator> |
120 | struct prior |
121 | { |
122 | typedef typename Derived_::template make< |
123 | typename result_of::prior< |
124 | typename Iterator::iterator_base_type |
125 | >::type>::type |
126 | type; |
127 | |
128 | BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED |
129 | static type |
130 | call(Iterator const& i) |
131 | { |
132 | return type(fusion::prior(i.iterator_base)); |
133 | } |
134 | }; |
135 | }; |
136 | }} |
137 | |
138 | #ifdef BOOST_FUSION_WORKAROUND_FOR_LWG_2408 |
139 | namespace std |
140 | { |
141 | template <typename Derived, typename Iterator, typename Category> |
142 | struct iterator_traits< ::boost::fusion::iterator_adapter<Derived, Iterator, Category> > |
143 | { }; |
144 | } |
145 | #endif |
146 | |
147 | #endif |
148 | |