1 /*=============================================================================
2 Copyright (c) 2011 Eric Niebler
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(BOOST_FUSION_SEGMENTED_ITERATOR_SEGMENTED_ITERATOR_HPP_INCLUDED)
8 #define BOOST_FUSION_SEGMENTED_ITERATOR_SEGMENTED_ITERATOR_HPP_INCLUDED
10 #include <boost/mpl/bool.hpp>
11 #include <boost/fusion/sequence/intrinsic_fwd.hpp>
12 #include <boost/fusion/iterator/iterator_facade.hpp>
13 #include <boost/fusion/iterator/deref.hpp>
14 #include <boost/fusion/iterator/deref_data.hpp>
15 #include <boost/fusion/iterator/key_of.hpp>
16 #include <boost/fusion/iterator/value_of.hpp>
17 #include <boost/fusion/iterator/value_of_data.hpp>
18 #include <boost/fusion/iterator/detail/segmented_equal_to.hpp>
20 namespace boost { namespace fusion
26 template <typename Stack>
27 struct segmented_next_impl;
30 // A segmented iterator wraps a "context", which is a cons list
31 // of ranges, the frontmost is range over values and the rest
32 // are ranges over internal segments.
33 template <typename Context>
34 struct segmented_iterator
35 : iterator_facade<segmented_iterator<Context>, forward_traversal_tag>
37 explicit segmented_iterator(Context const& ctx)
43 // return deref(begin(car(it.context)))
45 template <typename It>
49 typename result_of::deref<
50 typename It::context_type::car_type::begin_type
54 static type call(It const& it)
56 return *it.context.car.first;
62 // return deref_data(begin(car(it.context)))
64 template <typename It>
68 typename result_of::deref_data<
69 typename It::context_type::car_type::begin_type
73 static type call(It const& it)
75 return fusion::deref_data(it.context.car.first);
81 // return key_of(begin(car(it.context)))
83 template <typename It>
85 : result_of::key_of<typename It::context_type::car_type::begin_type>
90 // return value_of(begin(car(it.context)))
92 template <typename It>
94 : result_of::value_of<typename It::context_type::car_type::begin_type>
97 //auto value_of_data(it)
99 // return value_of_data(begin(car(it.context)))
101 template <typename It>
103 : result_of::value_of_data<typename It::context_type::car_type::begin_type>
106 // Compare all the segment iterators in each stack, starting with
111 , int Size1 = It1::context_type::size::value
112 , int Size2 = It2::context_type::size::value
118 template <typename It1, typename It2, int Size>
119 struct equal_to<It1, It2, Size, Size>
120 : detail::segmented_equal_to<
121 typename It1::context_type
122 , typename It2::context_type
126 template <typename It>
129 typedef detail::segmented_next_impl<typename It::context_type> impl;
130 typedef segmented_iterator<typename impl::type> type;
132 static type call(It const& it)
134 return type(impl::call(it.context));
138 typedef Context context_type;
139 context_type context;