advance.hpp 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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_1146)
  7. #define FUSION_ADVANCE_09172005_1146
  8. #include <boost/fusion/support/config.hpp>
  9. #include <boost/fusion/iterator/detail/advance.hpp>
  10. #include <boost/fusion/support/category_of.hpp>
  11. #include <boost/mpl/int.hpp>
  12. #include <boost/mpl/assert.hpp>
  13. #include <boost/type_traits/is_same.hpp>
  14. #include <boost/fusion/support/tag_of.hpp>
  15. namespace boost { namespace fusion
  16. {
  17. struct random_access_traversal_tag;
  18. // Special tags:
  19. struct iterator_facade_tag; // iterator facade tag
  20. struct boost_array_iterator_tag; // boost::array iterator tag
  21. struct mpl_iterator_tag; // mpl sequence iterator tag
  22. struct std_pair_iterator_tag; // std::pair iterator tag
  23. namespace extension
  24. {
  25. template <typename Tag>
  26. struct advance_impl
  27. {
  28. // default implementation
  29. template <typename Iterator, typename N>
  30. struct apply :
  31. mpl::if_c<
  32. (N::value > 0)
  33. , advance_detail::forward<Iterator, N::value>
  34. , advance_detail::backward<Iterator, N::value>
  35. >::type
  36. {
  37. BOOST_MPL_ASSERT_NOT((traits::is_random_access<Iterator>));
  38. };
  39. };
  40. template <>
  41. struct advance_impl<iterator_facade_tag>
  42. {
  43. template <typename Iterator, typename N>
  44. struct apply : Iterator::template advance<Iterator, N> {};
  45. };
  46. template <>
  47. struct advance_impl<boost_array_iterator_tag>;
  48. template <>
  49. struct advance_impl<mpl_iterator_tag>;
  50. template <>
  51. struct advance_impl<std_pair_iterator_tag>;
  52. }
  53. namespace result_of
  54. {
  55. template <typename Iterator, int N>
  56. struct advance_c
  57. : extension::advance_impl<typename detail::tag_of<Iterator>::type>::template apply<Iterator, mpl::int_<N> >
  58. {};
  59. template <typename Iterator, typename N>
  60. struct advance
  61. : extension::advance_impl<typename detail::tag_of<Iterator>::type>::template apply<Iterator, N>
  62. {};
  63. }
  64. template <int N, typename Iterator>
  65. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  66. inline typename result_of::advance_c<Iterator, N>::type const
  67. advance_c(Iterator const& i)
  68. {
  69. return result_of::advance_c<Iterator, N>::call(i);
  70. }
  71. template<typename N, typename Iterator>
  72. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  73. inline typename result_of::advance<Iterator, N>::type const
  74. advance(Iterator const& i)
  75. {
  76. return result_of::advance<Iterator, N>::call(i);
  77. }
  78. }} // namespace boost::fusion
  79. #endif