1 /*=============================================================================
2 Copyright (c) 2001-2011 Joel de Guzman
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_BOOST_TUPLE_ITERATOR_09262006_1851)
8 #define FUSION_BOOST_TUPLE_ITERATOR_09262006_1851
10 #include <boost/fusion/support/config.hpp>
11 #include <boost/fusion/iterator/iterator_facade.hpp>
12 #include <boost/type_traits/is_const.hpp>
13 #include <boost/type_traits/add_const.hpp>
14 #include <boost/mpl/identity.hpp>
15 #include <boost/mpl/if.hpp>
16 #include <boost/mpl/eval_if.hpp>
17 #include <boost/mpl/or.hpp>
18 #include <boost/mpl/plus.hpp>
19 #include <boost/mpl/int.hpp>
20 #include <boost/mpl/apply.hpp>
21 #include <boost/tuple/tuple.hpp>
23 namespace boost { namespace fusion
25 struct forward_traversal_tag;
30 struct boost_tuple_is_empty : mpl::false_ {};
33 struct boost_tuple_is_empty<tuples::null_type> : mpl::true_ {};
36 struct boost_tuple_is_empty<tuples::null_type const> : mpl::true_ {};
39 struct boost_tuple_is_empty<tuples::tuple<> > : mpl::true_ {};
42 struct boost_tuple_is_empty<tuples::tuple<> const> : mpl::true_ {};
45 template <typename Cons = tuples::null_type>
46 struct boost_tuple_iterator
47 : iterator_facade<boost_tuple_iterator<Cons>, forward_traversal_tag>
49 typedef Cons cons_type;
51 BOOST_FUSION_GPU_ENABLED
52 explicit boost_tuple_iterator(Cons& in_cons)
56 template <typename Iterator>
57 struct value_of : mpl::identity<typename Iterator::cons_type::head_type> {};
59 template <typename Iterator>
62 typedef typename value_of<Iterator>::type element;
66 is_const<typename Iterator::cons_type>
67 , typename tuples::access_traits<element>::const_type
68 , typename tuples::access_traits<element>::non_const_type
72 BOOST_FUSION_GPU_ENABLED
74 call(Iterator const& iter)
76 return iter.cons.get_head();
80 template <typename Iterator>
83 typedef typename Iterator::cons_type cons_type;
84 typedef typename cons_type::tail_type tail_type;
86 typedef boost_tuple_iterator<
87 typename mpl::eval_if<
89 , add_const<tail_type>
90 , mpl::identity<tail_type>
94 BOOST_FUSION_GPU_ENABLED
96 call(Iterator const& iter)
98 return type(iter.cons.get_tail());
102 template <typename I1, typename I2>
106 template <typename I1, typename I2>
107 struct lazy_next_distance
113 typename next<I1>::type,
119 template <typename I1, typename I2>
122 typedef typename mpl::eval_if<
123 boost::is_same<I1, I2>,
125 lazy_next_distance<I1, I2>
128 BOOST_FUSION_GPU_ENABLED
130 call(I1 const&, I2 const&)
137 // silence MSVC warning C4512: assignment operator could not be generated
138 boost_tuple_iterator& operator= (boost_tuple_iterator const&);
141 template <typename Null>
142 struct boost_tuple_null_iterator
143 : iterator_facade<boost_tuple_iterator<Null>, forward_traversal_tag>
145 typedef Null cons_type;
147 template <typename I1, typename I2>
152 detail::boost_tuple_is_empty<typename I1::cons_type>
153 , detail::boost_tuple_is_empty<typename I2::cons_type>
160 struct boost_tuple_iterator<tuples::null_type>
161 : boost_tuple_null_iterator<tuples::null_type>
163 template <typename Cons>
164 BOOST_FUSION_GPU_ENABLED
165 explicit boost_tuple_iterator(Cons const&) {}
169 struct boost_tuple_iterator<tuples::null_type const>
170 : boost_tuple_null_iterator<tuples::null_type const>
172 template <typename Cons>
173 BOOST_FUSION_GPU_ENABLED
174 explicit boost_tuple_iterator(Cons const&) {}
178 struct boost_tuple_iterator<tuples::tuple<> >
179 : boost_tuple_null_iterator<tuples::tuple<> >
181 template <typename Cons>
182 BOOST_FUSION_GPU_ENABLED
183 explicit boost_tuple_iterator(Cons const&) {}
187 struct boost_tuple_iterator<tuples::tuple<> const>
188 : boost_tuple_null_iterator<tuples::tuple<> const>
190 template <typename Cons>
191 BOOST_FUSION_GPU_ENABLED
192 explicit boost_tuple_iterator(Cons const&) {}