Imported Upstream version 1.57.0
[platform/upstream/boost.git] / boost / fusion / iterator / iterator_adapter.hpp
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/iterator/detail/advance.hpp>
12 #include <boost/fusion/iterator/iterator_facade.hpp>
13 #include <boost/type_traits/remove_const.hpp>
14
15 namespace boost { namespace fusion
16 {
17     template <typename Derived_, typename Iterator_,
18         typename Category = typename Iterator_::category>
19     struct iterator_adapter
20         : iterator_facade<Derived_, Category>
21     {
22         typedef typename
23             remove_const<Iterator_>::type
24         iterator_base_type;
25         iterator_base_type iterator_base;
26
27         BOOST_FUSION_GPU_ENABLED
28         iterator_adapter(iterator_base_type const& iterator_base_)
29             : iterator_base(iterator_base_) {}
30
31         // default implementation
32         template <typename I1, typename I2>
33         struct equal_to
34             : result_of::equal_to<
35                 typename I1::iterator_base_type
36               , typename I2::iterator_base_type
37             >
38         {};
39
40         // default implementation
41         template <typename Iterator, typename N>
42         struct advance
43         {
44             typedef typename Derived_::template make<
45                 typename result_of::advance<
46                     typename Iterator::iterator_base_type, N
47                 >::type>::type
48             type;
49
50             BOOST_FUSION_GPU_ENABLED
51             static type
52             call(Iterator const& it)
53             {
54                 return type(fusion::advance<N>(it.iterator_base));
55             }
56         };
57
58         // default implementation
59         template <typename First, typename Last>
60         struct distance
61             : result_of::distance<
62                 typename First::iterator_base_type
63               , typename Last::iterator_base_type
64             >
65         {};
66
67         // default implementation
68         template <typename Iterator>
69         struct value_of
70             : result_of::value_of<
71                 typename Iterator::iterator_base_type
72             >
73         {};
74
75         // default implementation
76         template <typename Iterator>
77         struct deref
78         {
79             typedef typename
80                 result_of::deref<
81                     typename Iterator::iterator_base_type
82                 >::type
83             type;
84
85             BOOST_FUSION_GPU_ENABLED
86             static type
87             call(Iterator const& it)
88             {
89                 return fusion::deref(it.iterator_base);
90             }
91         };
92
93         // default implementation
94         template <typename Iterator>
95         struct next
96         {
97             typedef typename Derived_::template make<
98                 typename result_of::next<
99                     typename Iterator::iterator_base_type
100                 >::type>::type
101             type;
102
103             BOOST_FUSION_GPU_ENABLED
104             static type
105             call(Iterator const& i)
106             {
107                 return type(fusion::next(i.iterator_base));
108             }
109         };
110
111         // default implementation
112         template <typename Iterator>
113         struct prior
114         {
115             typedef typename Derived_::template make<
116                 typename result_of::prior<
117                     typename Iterator::iterator_base_type
118                 >::type>::type
119             type;
120
121             BOOST_FUSION_GPU_ENABLED
122             static type
123             call(Iterator const& i)
124             {
125                 return type(fusion::prior(i.iterator_base));
126             }
127         };
128     };
129 }}
130
131 #endif