filter_iter.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #ifndef BOOST_MPL_AUX_FILTER_ITER_HPP_INCLUDED
  2. #define BOOST_MPL_AUX_FILTER_ITER_HPP_INCLUDED
  3. // Copyright Aleksey Gurtovoy 2000-2004
  4. //
  5. // Distributed under the Boost Software License, Version 1.0.
  6. // (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // See http://www.boost.org/libs/mpl for documentation.
  10. // $Id$
  11. // $Date$
  12. // $Revision$
  13. #include <boost/mpl/find_if.hpp>
  14. #include <boost/mpl/iterator_range.hpp>
  15. #include <boost/mpl/iterator_tags.hpp>
  16. #include <boost/mpl/deref.hpp>
  17. #include <boost/mpl/aux_/lambda_spec.hpp>
  18. #include <boost/mpl/aux_/config/ctps.hpp>
  19. #include <boost/type_traits/is_same.hpp>
  20. namespace boost { namespace mpl {
  21. namespace aux {
  22. template<
  23. typename Iterator
  24. , typename LastIterator
  25. , typename Predicate
  26. >
  27. struct filter_iter;
  28. template<
  29. typename Iterator
  30. , typename LastIterator
  31. , typename Predicate
  32. >
  33. struct next_filter_iter
  34. {
  35. typedef typename find_if<
  36. iterator_range<Iterator,LastIterator>
  37. , Predicate
  38. >::type base_iter_;
  39. typedef filter_iter<base_iter_,LastIterator,Predicate> type;
  40. };
  41. #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
  42. template<
  43. typename Iterator
  44. , typename LastIterator
  45. , typename Predicate
  46. >
  47. struct filter_iter
  48. {
  49. typedef Iterator base;
  50. typedef forward_iterator_tag category;
  51. typedef typename aux::next_filter_iter<
  52. typename mpl::next<base>::type
  53. , LastIterator
  54. , Predicate
  55. >::type next;
  56. typedef typename deref<base>::type type;
  57. };
  58. template<
  59. typename LastIterator
  60. , typename Predicate
  61. >
  62. struct filter_iter< LastIterator,LastIterator,Predicate >
  63. {
  64. typedef LastIterator base;
  65. typedef forward_iterator_tag category;
  66. };
  67. #else
  68. template< bool >
  69. struct filter_iter_impl
  70. {
  71. template<
  72. typename Iterator
  73. , typename LastIterator
  74. , typename Predicate
  75. >
  76. struct result_
  77. {
  78. typedef Iterator base;
  79. typedef forward_iterator_tag category;
  80. typedef typename next_filter_iter<
  81. typename mpl::next<Iterator>::type
  82. , LastIterator
  83. , Predicate
  84. >::type next;
  85. typedef typename deref<base>::type type;
  86. };
  87. };
  88. template<>
  89. struct filter_iter_impl< true >
  90. {
  91. template<
  92. typename Iterator
  93. , typename LastIterator
  94. , typename Predicate
  95. >
  96. struct result_
  97. {
  98. typedef Iterator base;
  99. typedef forward_iterator_tag category;
  100. };
  101. };
  102. template<
  103. typename Iterator
  104. , typename LastIterator
  105. , typename Predicate
  106. >
  107. struct filter_iter
  108. : filter_iter_impl<
  109. ::boost::is_same<Iterator,LastIterator>::value
  110. >::template result_< Iterator,LastIterator,Predicate >
  111. {
  112. };
  113. #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
  114. } // namespace aux
  115. BOOST_MPL_AUX_PASS_THROUGH_LAMBDA_SPEC(3, aux::filter_iter)
  116. }}
  117. #endif // BOOST_MPL_AUX_FILTER_ITER_HPP_INCLUDED