advance.hpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Joel de Guzman
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. ==============================================================================*/
  6. #if !defined(FUSION_ADVANCE_09172005_1149)
  7. #define FUSION_ADVANCE_09172005_1149
  8. #include <boost/mpl/int.hpp>
  9. #include <boost/mpl/if.hpp>
  10. #include <boost/mpl/eval_if.hpp>
  11. #include <boost/mpl/identity.hpp>
  12. #include <boost/fusion/iterator/next.hpp>
  13. #include <boost/fusion/iterator/prior.hpp>
  14. namespace boost { namespace fusion { namespace advance_detail
  15. {
  16. // Default advance implementation, perform next(i)
  17. // or prior(i) N times.
  18. template <typename Iterator, int N>
  19. struct forward;
  20. template <typename Iterator, int N>
  21. struct next_forward
  22. {
  23. typedef typename
  24. forward<
  25. typename result_of::next<Iterator>::type
  26. , N-1
  27. >::type
  28. type;
  29. };
  30. template <typename Iterator, int N>
  31. struct forward
  32. {
  33. typedef typename
  34. mpl::eval_if_c<
  35. (N == 0)
  36. , mpl::identity<Iterator>
  37. , next_forward<Iterator, N>
  38. >::type
  39. type;
  40. static type const&
  41. call(type const& i)
  42. {
  43. return i;
  44. }
  45. template <typename I>
  46. static type
  47. call(I const& i)
  48. {
  49. return call(fusion::next(i));
  50. }
  51. };
  52. template <typename Iterator, int N>
  53. struct backward;
  54. template <typename Iterator, int N>
  55. struct next_backward
  56. {
  57. typedef typename
  58. backward<
  59. typename result_of::prior<Iterator>::type
  60. , N+1
  61. >::type
  62. type;
  63. };
  64. template <typename Iterator, int N>
  65. struct backward
  66. {
  67. typedef typename
  68. mpl::eval_if_c<
  69. (N == 0)
  70. , mpl::identity<Iterator>
  71. , next_backward<Iterator, N>
  72. >::type
  73. type;
  74. static type const&
  75. call(type const& i)
  76. {
  77. return i;
  78. }
  79. template <typename I>
  80. static type
  81. call(I const& i)
  82. {
  83. return call(fusion::prior(i));
  84. }
  85. };
  86. }}}
  87. #endif