1 /*============================================================================= 2 Copyright (c) 2001-2006 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_ADVANCE_09172005_1149) 8 #define FUSION_ADVANCE_09172005_1149 9 10 #include <boost/mpl/int.hpp> 11 #include <boost/mpl/if.hpp> 12 #include <boost/mpl/eval_if.hpp> 13 #include <boost/mpl/identity.hpp> 14 #include <boost/fusion/iterator/next.hpp> 15 #include <boost/fusion/iterator/prior.hpp> 16 17 namespace boost { namespace fusion { namespace advance_detail 18 { 19 // Default advance implementation, perform next(i) 20 // or prior(i) N times. 21 22 template <typename Iterator, int N> 23 struct forward; 24 25 template <typename Iterator, int N> 26 struct next_forward 27 { 28 typedef typename 29 forward< 30 typename result_of::next<Iterator>::type 31 , N-1 32 >::type 33 type; 34 }; 35 36 template <typename Iterator, int N> 37 struct forward 38 { 39 typedef typename 40 mpl::eval_if_c< 41 (N == 0) 42 , mpl::identity<Iterator> 43 , next_forward<Iterator, N> 44 >::type 45 type; 46 47 static type const& callboost::fusion::advance_detail::forward48 call(type const& i) 49 { 50 return i; 51 } 52 53 template <typename I> 54 static type callboost::fusion::advance_detail::forward55 call(I const& i) 56 { 57 return call(fusion::next(i)); 58 } 59 }; 60 61 template <typename Iterator, int N> 62 struct backward; 63 64 template <typename Iterator, int N> 65 struct next_backward 66 { 67 typedef typename 68 backward< 69 typename result_of::prior<Iterator>::type 70 , N+1 71 >::type 72 type; 73 }; 74 75 template <typename Iterator, int N> 76 struct backward 77 { 78 typedef typename 79 mpl::eval_if_c< 80 (N == 0) 81 , mpl::identity<Iterator> 82 , next_backward<Iterator, N> 83 >::type 84 type; 85 86 static type const& callboost::fusion::advance_detail::backward87 call(type const& i) 88 { 89 return i; 90 } 91 92 template <typename I> 93 static type callboost::fusion::advance_detail::backward94 call(I const& i) 95 { 96 return call(fusion::prior(i)); 97 } 98 }; 99 100 }}} 101 102 #endif 103