• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*=============================================================================
2     Copyright (c) 2001-2011 Joel de Guzman
3 
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
9 
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>
17 #include <tuple>
18 #include <utility>
19 
20 namespace boost { namespace fusion
21 {
22     struct random_access_traversal_tag;
23 
24     template <typename Tuple, int Index>
25     struct std_tuple_iterator_identity;
26 
27     template <typename Tuple, int Index>
28     struct std_tuple_iterator
29         : iterator_facade<
30               std_tuple_iterator<Tuple, Index>
31             , random_access_traversal_tag>
32     {
33         typedef Tuple tuple_type;
34         static int const index = Index;
35         typedef std_tuple_iterator_identity<
36             typename add_const<Tuple>::type, Index>
37         identity;
38 
39         BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
std_tuple_iteratorboost::fusion::std_tuple_iterator40         explicit std_tuple_iterator(Tuple& tuple)
41           : tuple(tuple) {}
42 
43         Tuple& tuple;
44 
45         template <typename Iterator>
46         struct value_of
47           : std::tuple_element<Iterator::index,
48               typename remove_const<typename Iterator::tuple_type>::type> {};
49 
50         template <typename Iterator>
51         struct deref
52         {
53             typedef typename value_of<Iterator>::type element;
54             typedef typename
55                 mpl::if_<
56                     is_const<typename Iterator::tuple_type>
57                   , typename fusion::detail::cref_result<element>::type
58                   , typename fusion::detail::ref_result<element>::type
59                 >::type
60             type;
61 
62             BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
63             static type
callboost::fusion::std_tuple_iterator::deref64             call(Iterator const& iter)
65             {
66                 return std::get<Index>(iter.tuple);
67             }
68         };
69 
70         template <typename Iterator, typename N>
71         struct advance
72         {
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;
76 
77             BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
78             static type
callboost::fusion::std_tuple_iterator::advance79             call(Iterator const& i)
80             {
81                 return type(i.tuple);
82             }
83         };
84 
85         template <typename Iterator>
86         struct next : advance<Iterator, mpl::int_<1>> {};
87 
88         template <typename Iterator>
89         struct prior : advance<Iterator, mpl::int_<-1>> {};
90 
91         template <typename I1, typename I2>
92         struct equal_to
93             : is_same<typename I1::identity, typename I2::identity> {};
94 
95         template <typename First, typename Last>
96         struct distance
97         {
98             typedef mpl::int_<Last::index-First::index> type;
99 
100             BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
101             static type
callboost::fusion::std_tuple_iterator::distance102             call(First const&, Last const&)
103             {
104                 return type();
105             }
106         };
107     };
108 }}
109 
110 #ifdef BOOST_FUSION_WORKAROUND_FOR_LWG_2408
111 namespace std
112 {
113     template <typename Tuple, int Index>
114     struct iterator_traits< ::boost::fusion::std_tuple_iterator<Tuple, Index> >
115     { };
116 }
117 #endif
118 
119 #endif
120 
121 
122