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/fusion/support/config.hpp>
11 #include <boost/mpl/bool.hpp>
12 #include <boost/fusion/sequence/intrinsic_fwd.hpp>
13 #include <boost/fusion/iterator/iterator_facade.hpp>
14 #include <boost/fusion/iterator/deref.hpp>
15 #include <boost/fusion/iterator/deref_data.hpp>
16 #include <boost/fusion/iterator/key_of.hpp>
17 #include <boost/fusion/iterator/value_of.hpp>
18 #include <boost/fusion/iterator/value_of_data.hpp>
19 #include <boost/fusion/iterator/detail/segmented_equal_to.hpp>
21 namespace boost { namespace fusion
27 template <typename Stack>
28 struct segmented_next_impl;
31 // A segmented iterator wraps a "context", which is a cons list
32 // of ranges, the frontmost is range over values and the rest
33 // are ranges over internal segments.
34 template <typename Context>
35 struct segmented_iterator
36 : iterator_facade<segmented_iterator<Context>, forward_traversal_tag>
38 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED explicit segmented_iterator(Context const& ctx)
44 // return deref(begin(car(it.context)))
46 template <typename It>
50 typename result_of::deref<
51 typename It::context_type::car_type::begin_type
55 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
56 static type call(It const& it)
58 return *it.context.car.first;
64 // return deref_data(begin(car(it.context)))
66 template <typename It>
70 typename result_of::deref_data<
71 typename It::context_type::car_type::begin_type
75 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
76 static type call(It const& it)
78 return fusion::deref_data(it.context.car.first);
84 // return key_of(begin(car(it.context)))
86 template <typename It>
88 : result_of::key_of<typename It::context_type::car_type::begin_type>
93 // return value_of(begin(car(it.context)))
95 template <typename It>
97 : result_of::value_of<typename It::context_type::car_type::begin_type>
100 //auto value_of_data(it)
102 // return value_of_data(begin(car(it.context)))
104 template <typename It>
106 : result_of::value_of_data<typename It::context_type::car_type::begin_type>
109 // Compare all the segment iterators in each stack, starting with
114 , int Size1 = It1::context_type::size::value
115 , int Size2 = It2::context_type::size::value
121 template <typename It1, typename It2, int Size>
122 struct equal_to<It1, It2, Size, Size>
123 : detail::segmented_equal_to<
124 typename It1::context_type
125 , typename It2::context_type
129 template <typename It>
132 typedef detail::segmented_next_impl<typename It::context_type> impl;
133 typedef segmented_iterator<typename impl::type> type;
135 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
136 static type call(It const& it)
138 return type(impl::call(it.context));
142 typedef Context context_type;
143 context_type context;