1 /*=============================================================================
2 Copyright (c) 2005-2012 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_DEQUE_ITERATOR_26112006_2154)
9 #define BOOST_FUSION_DEQUE_ITERATOR_26112006_2154
11 #include <boost/fusion/support/config.hpp>
12 #include <boost/fusion/iterator/iterator_facade.hpp>
13 #include <boost/fusion/container/deque/detail/keyed_element.hpp>
14 #include <boost/mpl/int.hpp>
15 #include <boost/mpl/minus.hpp>
16 #include <boost/mpl/equal_to.hpp>
17 #include <boost/mpl/identity.hpp>
18 #include <boost/mpl/if.hpp>
19 #include <boost/type_traits/is_const.hpp>
20 #include <boost/type_traits/add_const.hpp>
21 #include <boost/type_traits/add_reference.hpp>
23 namespace boost { namespace fusion {
25 struct bidirectional_traversal_tag;
27 template <typename Seq, int Pos>
29 : iterator_facade<deque_iterator<Seq, Pos>, bidirectional_traversal_tag>
32 typedef mpl::int_<Pos> index;
34 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
35 deque_iterator(Seq& seq)
39 template<typename Iterator>
41 : detail::keyed_element_value_at<
42 typename Iterator::sequence, typename Iterator::index>
45 template<typename Iterator>
48 typedef typename detail::keyed_element_value_at<
49 typename Iterator::sequence, typename Iterator::index>::type element_type;
51 typedef typename add_reference<
52 typename mpl::eval_if<
53 is_const<typename Iterator::sequence>,
54 add_const<element_type>,
55 mpl::identity<element_type> >::type>::type type;
57 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
59 call(Iterator const& it)
61 return it.seq_.get(typename Iterator::index());
65 template <typename Iterator, typename N>
68 typedef typename Iterator::index index;
69 typedef typename Iterator::sequence sequence;
70 typedef deque_iterator<sequence, index::value + N::value> type;
72 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
74 call(Iterator const& i)
80 template<typename Iterator>
82 : advance<Iterator, mpl::int_<1> >
85 template<typename Iterator>
87 : advance<Iterator, mpl::int_<-1> >
90 template <typename I1, typename I2>
91 struct distance : mpl::minus<typename I2::index, typename I1::index>
95 typename I2::index, typename I1::index
99 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
101 call(I1 const&, I2 const&)
107 template<typename I1, typename I2>
109 : mpl::equal_to<typename I1::index, typename I2::index>
114 // silence MSVC warning C4512: assignment operator could not be generated
115 BOOST_DELETED_FUNCTION(deque_iterator& operator= (deque_iterator const&))
120 #ifdef BOOST_FUSION_WORKAROUND_FOR_LWG_2408
123 template <typename Seq, int Pos>
124 struct iterator_traits< ::boost::fusion::deque_iterator<Seq, Pos> >