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