1 /*============================================================================= 2 Copyright (c) 2001-2006 Joel de Guzman 3 Copyright (c) 2005-2006 Dan Marsden 4 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 10 11 #include <boost/fusion/iterator/iterator_facade.hpp> 12 #include <boost/fusion/container/deque/detail/keyed_element.hpp> 13 #include <boost/mpl/minus.hpp> 14 #include <boost/mpl/equal_to.hpp> 15 #include <boost/type_traits/is_const.hpp> 16 17 namespace boost { namespace fusion { 18 19 struct bidirectional_traversal_tag; 20 21 template<typename Seq, int Pos> 22 struct deque_iterator 23 : iterator_facade<deque_iterator<Seq, Pos>, bidirectional_traversal_tag> 24 { 25 typedef Seq sequence; 26 typedef mpl::int_<Pos> index; 27 deque_iteratorboost::fusion::deque_iterator28 deque_iterator(Seq& seq) 29 : seq_(seq) 30 {} 31 32 template<typename Iterator> 33 struct value_of 34 : detail::keyed_element_value_at< 35 typename Iterator::sequence, typename Iterator::index> 36 {}; 37 38 template<typename Iterator> 39 struct deref 40 { 41 typedef typename detail::keyed_element_value_at< 42 typename Iterator::sequence, typename Iterator::index>::type element_type; 43 44 typedef typename add_reference< 45 typename mpl::eval_if< 46 is_const<typename Iterator::sequence>, 47 add_const<element_type>, 48 mpl::identity<element_type> >::type>::type type; 49 50 static type callboost::fusion::deque_iterator::deref51 call(Iterator const& it) 52 { 53 return it.seq_.get(typename Iterator::index()); 54 } 55 }; 56 57 template <typename Iterator, typename N> 58 struct advance 59 { 60 typedef typename Iterator::index index; 61 typedef typename Iterator::sequence sequence; 62 typedef deque_iterator<sequence, index::value + N::value> type; 63 64 static type callboost::fusion::deque_iterator::advance65 call(Iterator const& i) 66 { 67 return type(i.seq_); 68 } 69 }; 70 71 template<typename Iterator> 72 struct next 73 : advance<Iterator, mpl::int_<1> > 74 {}; 75 76 template<typename Iterator> 77 struct prior 78 : advance<Iterator, mpl::int_<-1> > 79 {}; 80 81 template <typename I1, typename I2> 82 struct distance : mpl::minus<typename I2::index, typename I1::index> 83 { 84 typedef typename 85 mpl::minus< 86 typename I2::index, typename I1::index 87 >::type 88 type; 89 90 static type callboost::fusion::deque_iterator::distance91 call(I1 const&, I2 const&) 92 { 93 return type(); 94 } 95 }; 96 97 template<typename I1, typename I2> 98 struct equal_to 99 : mpl::equal_to<typename I1::index, typename I2::index> 100 {}; 101 102 Seq& seq_; 103 104 private: 105 // silence MSVC warning C4512: assignment operator could not be generated 106 deque_iterator& operator= (deque_iterator const&); 107 }; 108 109 }} 110 111 #endif 112