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>
46 struct boost_tuple_iterator_identity;
48 template <typename Cons = tuples::null_type>
49 struct boost_tuple_iterator
50 : iterator_facade<boost_tuple_iterator<Cons>, forward_traversal_tag>
52 typedef Cons cons_type;
54 typedef boost_tuple_iterator_identity<
55 typename add_const<Cons>::type> identity;
57 BOOST_FUSION_GPU_ENABLED
58 explicit boost_tuple_iterator(Cons& in_cons)
62 template <typename Iterator>
63 struct value_of : mpl::identity<typename Iterator::cons_type::head_type> {};
65 template <typename Iterator>
68 typedef typename value_of<Iterator>::type element;
72 is_const<typename Iterator::cons_type>
73 , typename tuples::access_traits<element>::const_type
74 , typename tuples::access_traits<element>::non_const_type
78 BOOST_FUSION_GPU_ENABLED
80 call(Iterator const& iter)
82 return iter.cons.get_head();
86 template <typename Iterator>
89 typedef typename Iterator::cons_type cons_type;
90 typedef typename cons_type::tail_type tail_type;
92 typedef boost_tuple_iterator<
93 typename mpl::eval_if<
95 , add_const<tail_type>
96 , mpl::identity<tail_type>
100 BOOST_FUSION_GPU_ENABLED
102 call(Iterator const& iter)
104 return type(iter.cons.get_tail());
108 template <typename I1, typename I2>
112 template <typename I1, typename I2>
113 struct lazy_next_distance
119 typename next<I1>::type,
125 template <typename I1, typename I2>
128 typedef typename mpl::eval_if<
129 boost::is_same<I1, I2>,
131 lazy_next_distance<I1, I2>
134 BOOST_FUSION_GPU_ENABLED
136 call(I1 const&, I2 const&)
142 template <typename I1, typename I2>
144 : is_same<typename I1::identity, typename I2::identity>
148 // silence MSVC warning C4512: assignment operator could not be generated
149 boost_tuple_iterator& operator= (boost_tuple_iterator const&);
152 template <typename Null>
153 struct boost_tuple_null_iterator
154 : iterator_facade<boost_tuple_iterator<Null>, forward_traversal_tag>
156 typedef Null cons_type;
158 typedef boost_tuple_iterator_identity<
159 typename add_const<Null>::type> identity;
161 template <typename I1, typename I2>
166 detail::boost_tuple_is_empty<typename I1::cons_type>
167 , detail::boost_tuple_is_empty<typename I2::cons_type>
174 struct boost_tuple_iterator<tuples::null_type>
175 : boost_tuple_null_iterator<tuples::null_type>
177 template <typename Cons>
178 BOOST_FUSION_GPU_ENABLED
179 explicit boost_tuple_iterator(Cons const&) {}
183 struct boost_tuple_iterator<tuples::null_type const>
184 : boost_tuple_null_iterator<tuples::null_type const>
186 template <typename Cons>
187 BOOST_FUSION_GPU_ENABLED
188 explicit boost_tuple_iterator(Cons const&) {}
192 struct boost_tuple_iterator<tuples::tuple<> >
193 : boost_tuple_null_iterator<tuples::tuple<> >
195 template <typename Cons>
196 BOOST_FUSION_GPU_ENABLED
197 explicit boost_tuple_iterator(Cons const&) {}
201 struct boost_tuple_iterator<tuples::tuple<> const>
202 : boost_tuple_null_iterator<tuples::tuple<> const>
204 template <typename Cons>
205 BOOST_FUSION_GPU_ENABLED
206 explicit boost_tuple_iterator(Cons const&) {}
210 #ifdef BOOST_FUSION_WORKAROUND_FOR_LWG_2408
213 template <typename Cons>
214 struct iterator_traits< ::boost::fusion::boost_tuple_iterator<Cons> >