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_STD_TUPLE_ITERATOR_09112011_1905)
8 #define FUSION_STD_TUPLE_ITERATOR_09112011_1905
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/remove_const.hpp>
14 #include <boost/fusion/support/detail/access.hpp>
15 #include <boost/mpl/int.hpp>
16 #include <boost/mpl/if.hpp>
20 namespace boost { namespace fusion
22 struct random_access_traversal_tag;
24 template <typename Tuple, int Index>
25 struct std_tuple_iterator_identity;
27 template <typename Tuple, int Index>
28 struct std_tuple_iterator
30 std_tuple_iterator<Tuple, Index>
31 , random_access_traversal_tag>
33 typedef Tuple tuple_type;
34 static int const index = Index;
35 typedef std_tuple_iterator_identity<
36 typename add_const<Tuple>::type, Index>
39 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
40 explicit std_tuple_iterator(Tuple& tuple)
45 template <typename Iterator>
47 : std::tuple_element<Iterator::index,
48 typename remove_const<typename Iterator::tuple_type>::type> {};
50 template <typename Iterator>
53 typedef typename value_of<Iterator>::type element;
56 is_const<typename Iterator::tuple_type>
57 , typename fusion::detail::cref_result<element>::type
58 , typename fusion::detail::ref_result<element>::type
62 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
64 call(Iterator const& iter)
66 return std::get<Index>(iter.tuple);
70 template <typename Iterator, typename N>
73 static int const index = Iterator::index;
74 typedef typename Iterator::tuple_type tuple_type;
75 typedef std_tuple_iterator<tuple_type, index+N::value> type;
77 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
79 call(Iterator const& i)
85 template <typename Iterator>
86 struct next : advance<Iterator, mpl::int_<1>> {};
88 template <typename Iterator>
89 struct prior : advance<Iterator, mpl::int_<-1>> {};
91 template <typename I1, typename I2>
93 : is_same<typename I1::identity, typename I2::identity> {};
95 template <typename First, typename Last>
98 typedef mpl::int_<Last::index-First::index> type;
100 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
102 call(First const&, Last const&)
110 #ifdef BOOST_FUSION_WORKAROUND_FOR_LWG_2408
113 template <typename Tuple, int Index>
114 struct iterator_traits< ::boost::fusion::std_tuple_iterator<Tuple, Index> >