advance.hpp 2.6 KB

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