next_impl.hpp 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*=============================================================================
  2. Copyright (c) 2007 Tobias Schwinger
  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(BOOST_FUSION_REPETITIVE_VIEW_NEXT_IMPL_HPP_INCLUDED)
  7. #define BOOST_FUSION_REPETITIVE_VIEW_NEXT_IMPL_HPP_INCLUDED
  8. #include <boost/fusion/support/config.hpp>
  9. #include <boost/fusion/iterator/next.hpp>
  10. #include <boost/fusion/iterator/equal_to.hpp>
  11. namespace boost { namespace fusion
  12. {
  13. struct repetitive_view_iterator_tag;
  14. template <typename Sequence, typename Pos>
  15. struct repetitive_view_iterator;
  16. namespace extension
  17. {
  18. template <typename Tag>
  19. struct next_impl;
  20. template <>
  21. struct next_impl<repetitive_view_iterator_tag>
  22. {
  23. template<typename Iterator,
  24. bool Last = result_of::equal_to<typename Iterator::end_type,
  25. typename result_of::next<
  26. typename Iterator::pos_type
  27. >::type>::value >
  28. struct apply_nonempty // <Iterator,false>
  29. {
  30. // advanvce to next position
  31. typedef repetitive_view_iterator<
  32. typename Iterator::sequence_type,
  33. typename result_of::next<typename Iterator::pos_type>::type
  34. >
  35. type;
  36. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  37. static type call(Iterator const& i)
  38. {
  39. return type(i.seq, next(i.pos));
  40. }
  41. };
  42. template <typename Iterator>
  43. struct apply_nonempty<Iterator,true>
  44. {
  45. // reset to beginning
  46. typedef repetitive_view_iterator<
  47. typename Iterator::sequence_type,
  48. typename Iterator::first_type
  49. >
  50. type;
  51. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  52. static type call(Iterator const& i)
  53. {
  54. return type(i.seq);
  55. }
  56. };
  57. template <typename Iterator,
  58. bool Empty = result_of::equal_to<typename Iterator::end_type,
  59. typename Iterator::pos_type>::value >
  60. struct apply // <Iterator,false>
  61. : apply_nonempty<Iterator>
  62. { };
  63. template <typename Iterator>
  64. struct apply<Iterator,true>
  65. {
  66. // eps^n = eps
  67. typedef Iterator type;
  68. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  69. static type call(Iterator const& i)
  70. {
  71. return type(i);
  72. }
  73. };
  74. };
  75. }
  76. }}
  77. #endif