1 /*=============================================================================
2 Copyright (c) 2001-2011 Joel de Guzman
3 Copyright (c) 2005-2006 Dan Marsden
5 Distributed under the Boost Software License, Version 1.0. (See accompanying
6 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 ==============================================================================*/
8 #if !defined(BOOST_FUSION_ARRAY_ITERATOR_26122005_2250)
9 #define BOOST_FUSION_ARRAY_ITERATOR_26122005_2250
11 #include <boost/fusion/support/config.hpp>
13 #include <boost/config.hpp>
14 #include <boost/mpl/int.hpp>
15 #include <boost/mpl/assert.hpp>
16 #include <boost/mpl/if.hpp>
17 #include <boost/mpl/minus.hpp>
18 #include <boost/type_traits/is_const.hpp>
19 #include <boost/fusion/iterator/iterator_facade.hpp>
21 namespace boost { namespace fusion
23 struct random_access_traversal_tag;
25 template <typename Array, int Pos>
27 : iterator_facade<array_iterator<Array, Pos>, random_access_traversal_tag>
29 BOOST_MPL_ASSERT_RELATION(Pos, >=, 0);
30 BOOST_MPL_ASSERT_RELATION(Pos, <=, static_cast<int>(Array::static_size));
32 typedef mpl::int_<Pos> index;
33 typedef Array array_type;
35 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
36 array_iterator(Array& a)
41 template <typename Iterator>
44 typedef typename Iterator::array_type array_type;
45 typedef typename array_type::value_type type;
48 template <typename Iterator>
51 typedef typename Iterator::array_type array_type;
55 , typename array_type::const_reference
56 , typename array_type::reference
60 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
62 call(Iterator const & it)
64 return it.array[Iterator::index::value];
68 template <typename Iterator, typename N>
71 typedef typename Iterator::index index;
72 typedef typename Iterator::array_type array_type;
73 typedef array_iterator<array_type, index::value + N::value> type;
75 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
77 call(Iterator const& i)
83 template <typename Iterator>
84 struct next : advance<Iterator, mpl::int_<1> > {};
86 template <typename Iterator>
87 struct prior : advance<Iterator, mpl::int_<-1> > {};
89 template <typename I1, typename I2>
90 struct distance : mpl::minus<typename I2::index, typename I1::index>
94 typename I2::index, typename I1::index
98 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
100 call(I1 const&, I2 const&)
108 array_iterator<Array, Pos>& operator=(array_iterator<Array, Pos> const&);
112 #ifdef BOOST_FUSION_WORKAROUND_FOR_LWG_2408
115 template <typename Array, int Pos>
116 struct iterator_traits< ::boost::fusion::array_iterator<Array, Pos> >