iterator_adapter.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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_ITERATOR_ADAPTER_08112011_0942)
  7. #define FUSION_ITERATOR_ADAPTER_08112011_0942
  8. #include <boost/fusion/iterator/detail/advance.hpp>
  9. #include <boost/fusion/iterator/iterator_facade.hpp>
  10. #include <boost/type_traits/remove_const.hpp>
  11. namespace boost { namespace fusion
  12. {
  13. template <typename Derived_, typename Iterator_,
  14. typename Category = typename Iterator_::category>
  15. struct iterator_adapter
  16. : iterator_facade<Derived_, Category>
  17. {
  18. typedef typename
  19. remove_const<Iterator_>::type
  20. iterator_base_type;
  21. iterator_base_type iterator_base;
  22. iterator_adapter(iterator_base_type const& iterator_base_)
  23. : iterator_base(iterator_base_) {}
  24. // default implementation
  25. template <typename I1, typename I2>
  26. struct equal_to
  27. : result_of::equal_to<
  28. typename I1::iterator_base_type
  29. , typename I2::iterator_base_type
  30. >
  31. {};
  32. // default implementation
  33. template <typename Iterator, typename N>
  34. struct advance
  35. {
  36. typedef typename Derived_::template make<
  37. typename result_of::advance<
  38. typename Iterator::iterator_base_type, N
  39. >::type>::type
  40. type;
  41. static type
  42. call(Iterator const& it)
  43. {
  44. return type(fusion::advance<N>(it.iterator_base));
  45. }
  46. };
  47. // default implementation
  48. template <typename First, typename Last>
  49. struct distance
  50. : result_of::distance<
  51. typename First::iterator_base_type
  52. , typename Last::iterator_base_type
  53. >
  54. {};
  55. // default implementation
  56. template <typename Iterator>
  57. struct value_of
  58. : result_of::value_of<
  59. typename Iterator::iterator_base_type
  60. >
  61. {};
  62. // default implementation
  63. template <typename Iterator>
  64. struct deref
  65. {
  66. typedef typename
  67. result_of::deref<
  68. typename Iterator::iterator_base_type
  69. >::type
  70. type;
  71. static type
  72. call(Iterator const& it)
  73. {
  74. return fusion::deref(it.iterator_base);
  75. }
  76. };
  77. // default implementation
  78. template <typename Iterator>
  79. struct next
  80. {
  81. typedef typename Derived_::template make<
  82. typename result_of::next<
  83. typename Iterator::iterator_base_type
  84. >::type>::type
  85. type;
  86. static type
  87. call(Iterator const& i)
  88. {
  89. return type(fusion::next(i.iterator_base));
  90. }
  91. };
  92. // default implementation
  93. template <typename Iterator>
  94. struct prior
  95. {
  96. typedef typename Derived_::template make<
  97. typename result_of::prior<
  98. typename Iterator::iterator_base_type
  99. >::type>::type
  100. type;
  101. static type
  102. call(Iterator const& i)
  103. {
  104. return type(fusion::prior(i.iterator_base));
  105. }
  106. };
  107. };
  108. }}
  109. #endif