deque_iterator.hpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*=============================================================================
  2. Copyright (c) 2005-2012 Joel de Guzman
  3. Copyright (c) 2005-2006 Dan Marsden
  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(BOOST_FUSION_DEQUE_ITERATOR_26112006_2154)
  8. #define BOOST_FUSION_DEQUE_ITERATOR_26112006_2154
  9. #include <boost/fusion/support/config.hpp>
  10. #include <boost/fusion/iterator/iterator_facade.hpp>
  11. #include <boost/fusion/container/deque/detail/keyed_element.hpp>
  12. #include <boost/mpl/int.hpp>
  13. #include <boost/mpl/minus.hpp>
  14. #include <boost/mpl/equal_to.hpp>
  15. #include <boost/mpl/identity.hpp>
  16. #include <boost/mpl/if.hpp>
  17. #include <boost/type_traits/is_const.hpp>
  18. #include <boost/type_traits/add_const.hpp>
  19. #include <boost/type_traits/add_reference.hpp>
  20. #ifdef _MSC_VER
  21. # pragma warning(push)
  22. # pragma warning(disable: 4512) // assignment operator could not be generated.
  23. #endif
  24. namespace boost { namespace fusion {
  25. struct bidirectional_traversal_tag;
  26. template <typename Seq, int Pos>
  27. struct deque_iterator
  28. : iterator_facade<deque_iterator<Seq, Pos>, bidirectional_traversal_tag>
  29. {
  30. typedef Seq sequence;
  31. typedef mpl::int_<Pos> index;
  32. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  33. deque_iterator(Seq& seq)
  34. : seq_(seq)
  35. {}
  36. template<typename Iterator>
  37. struct value_of
  38. : detail::keyed_element_value_at<
  39. typename Iterator::sequence, typename Iterator::index>
  40. {};
  41. template<typename Iterator>
  42. struct deref
  43. {
  44. typedef typename detail::keyed_element_value_at<
  45. typename Iterator::sequence, typename Iterator::index>::type element_type;
  46. typedef typename add_reference<
  47. typename mpl::eval_if<
  48. is_const<typename Iterator::sequence>,
  49. add_const<element_type>,
  50. mpl::identity<element_type> >::type>::type type;
  51. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  52. static type
  53. call(Iterator const& it)
  54. {
  55. return it.seq_.get(typename Iterator::index());
  56. }
  57. };
  58. template <typename Iterator, typename N>
  59. struct advance
  60. {
  61. typedef typename Iterator::index index;
  62. typedef typename Iterator::sequence sequence;
  63. typedef deque_iterator<sequence, index::value + N::value> type;
  64. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  65. static type
  66. call(Iterator const& i)
  67. {
  68. return type(i.seq_);
  69. }
  70. };
  71. template<typename Iterator>
  72. struct next
  73. : advance<Iterator, mpl::int_<1> >
  74. {};
  75. template<typename Iterator>
  76. struct prior
  77. : advance<Iterator, mpl::int_<-1> >
  78. {};
  79. template <typename I1, typename I2>
  80. struct distance : mpl::minus<typename I2::index, typename I1::index>
  81. {
  82. typedef typename
  83. mpl::minus<
  84. typename I2::index, typename I1::index
  85. >::type
  86. type;
  87. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  88. static type
  89. call(I1 const&, I2 const&)
  90. {
  91. return type();
  92. }
  93. };
  94. template<typename I1, typename I2>
  95. struct equal_to
  96. : mpl::equal_to<typename I1::index, typename I2::index>
  97. {};
  98. Seq& seq_;
  99. };
  100. }}
  101. #ifdef _MSC_VER
  102. # pragma warning(pop)
  103. #endif
  104. #ifdef BOOST_FUSION_WORKAROUND_FOR_LWG_2408
  105. namespace std
  106. {
  107. template <typename Seq, int Pos>
  108. struct iterator_traits< ::boost::fusion::deque_iterator<Seq, Pos> >
  109. { };
  110. }
  111. #endif
  112. #endif