1 2 #ifndef BOOST_MPL_AUX_SINGLE_ELEMENT_ITER_HPP_INCLUDED 3 #define BOOST_MPL_AUX_SINGLE_ELEMENT_ITER_HPP_INCLUDED 4 5 // Copyright Aleksey Gurtovoy 2000-2004 6 // 7 // Distributed under the Boost Software License, Version 1.0. 8 // (See accompanying file LICENSE_1_0.txt or copy at 9 // http://www.boost.org/LICENSE_1_0.txt) 10 // 11 // See http://www.boost.org/libs/mpl for documentation. 12 13 // $Id$ 14 // $Date$ 15 // $Revision$ 16 17 #include <boost/mpl/iterator_tags.hpp> 18 #include <boost/mpl/advance_fwd.hpp> 19 #include <boost/mpl/distance_fwd.hpp> 20 #include <boost/mpl/next_prior.hpp> 21 #include <boost/mpl/deref.hpp> 22 #include <boost/mpl/int.hpp> 23 #include <boost/mpl/aux_/nttp_decl.hpp> 24 #include <boost/mpl/aux_/value_wknd.hpp> 25 #include <boost/mpl/aux_/config/ctps.hpp> 26 27 namespace boost { namespace mpl { 28 29 #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) 30 31 namespace aux { 32 33 template< typename T, BOOST_MPL_AUX_NTTP_DECL(int, is_last_) > 34 struct sel_iter; 35 36 template< typename T > 37 struct sel_iter<T,0> 38 { 39 typedef random_access_iterator_tag category; 40 typedef sel_iter<T,1> next; 41 typedef T type; 42 }; 43 44 template< typename T > 45 struct sel_iter<T,1> 46 { 47 typedef random_access_iterator_tag category; 48 typedef sel_iter<T,0> prior; 49 }; 50 51 } // namespace aux 52 53 template< typename T, BOOST_MPL_AUX_NTTP_DECL(int, is_last_), typename Distance > 54 struct advance< aux::sel_iter<T,is_last_>,Distance> 55 { 56 typedef aux::sel_iter< 57 T 58 , ( is_last_ + BOOST_MPL_AUX_NESTED_VALUE_WKND(int, Distance) ) 59 > type; 60 }; 61 62 template< 63 typename T 64 , BOOST_MPL_AUX_NTTP_DECL(int, l1) 65 , BOOST_MPL_AUX_NTTP_DECL(int, l2) 66 > 67 struct distance< aux::sel_iter<T,l1>, aux::sel_iter<T,l2> > 68 : int_<( l2 - l1 )> 69 { 70 }; 71 72 #else 73 74 namespace aux { 75 76 struct sel_iter_tag; 77 78 template< typename T, BOOST_MPL_AUX_NTTP_DECL(int, is_last_) > 79 struct sel_iter 80 { 81 enum { pos_ = is_last_ }; 82 typedef aux::sel_iter_tag tag; 83 typedef random_access_iterator_tag category; 84 85 typedef sel_iter<T,(is_last_ + 1)> next; 86 typedef sel_iter<T,(is_last_ - 1)> prior; 87 typedef T type; 88 }; 89 90 } // namespace aux 91 92 template<> struct advance_impl<aux::sel_iter_tag> 93 { 94 template< typename Iterator, typename N > struct apply 95 { 96 enum { pos_ = Iterator::pos_, n_ = N::value }; 97 typedef aux::sel_iter< 98 typename Iterator::type 99 , (pos_ + n_) 100 > type; 101 }; 102 }; 103 104 template<> struct distance_impl<aux::sel_iter_tag> 105 { 106 template< typename Iter1, typename Iter2 > struct apply 107 { 108 enum { pos1_ = Iter1::pos_, pos2_ = Iter2::pos_ }; 109 typedef int_<( pos2_ - pos1_ )> type; 110 BOOST_STATIC_CONSTANT(int, value = ( pos2_ - pos1_ )); 111 }; 112 }; 113 114 #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION 115 116 }} 117 118 #endif // BOOST_MPL_AUX_SINGLE_ELEMENT_ITER_HPP_INCLUDED 119