filter_view_iterator.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Joel de Guzman
  3. Copyright (c) 2018 Kohei Takahashi
  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(FUSION_FILTER_VIEW_ITERATOR_05062005_0849)
  8. #define FUSION_FILTER_VIEW_ITERATOR_05062005_0849
  9. #include <boost/fusion/support/config.hpp>
  10. #include <boost/fusion/iterator/mpl/convert_iterator.hpp>
  11. #include <boost/fusion/iterator/value_of.hpp>
  12. #include <boost/fusion/support/iterator_base.hpp>
  13. #include <boost/fusion/algorithm/query/detail/find_if.hpp>
  14. #include <boost/mpl/lambda.hpp>
  15. #include <boost/mpl/quote.hpp>
  16. #include <boost/mpl/bind.hpp>
  17. #include <boost/mpl/placeholders.hpp>
  18. #include <boost/fusion/view/filter_view/detail/deref_impl.hpp>
  19. #include <boost/fusion/view/filter_view/detail/next_impl.hpp>
  20. #include <boost/fusion/view/filter_view/detail/value_of_impl.hpp>
  21. #include <boost/fusion/view/filter_view/detail/equal_to_impl.hpp>
  22. #include <boost/fusion/view/filter_view/detail/deref_data_impl.hpp>
  23. #include <boost/fusion/view/filter_view/detail/value_of_data_impl.hpp>
  24. #include <boost/fusion/view/filter_view/detail/key_of_impl.hpp>
  25. namespace boost { namespace fusion
  26. {
  27. struct filter_view_iterator_tag;
  28. struct forward_traversal_tag;
  29. template <typename Category, typename First, typename Last, typename Pred>
  30. struct filter_iterator : iterator_base<filter_iterator<Category, First, Last, Pred> >
  31. {
  32. typedef convert_iterator<First> first_converter;
  33. typedef typename first_converter::type first_iter;
  34. typedef convert_iterator<Last> last_converter;
  35. typedef typename last_converter::type last_iter;
  36. typedef filter_view_iterator_tag fusion_tag;
  37. typedef Category category;
  38. typedef
  39. detail::static_find_if<
  40. first_iter
  41. , last_iter
  42. , mpl::bind1<
  43. typename mpl::lambda<Pred>::type
  44. , mpl::bind1<mpl::quote1<result_of::value_of>,mpl::_1>
  45. >
  46. >
  47. filter;
  48. typedef typename filter::type first_type;
  49. typedef last_iter last_type;
  50. typedef Pred pred_type;
  51. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  52. filter_iterator(First const& in_first)
  53. : first(filter::iter_call(first_converter::call(in_first))) {}
  54. first_type first;
  55. private:
  56. // silence MSVC warning C4512: assignment operator could not be generated
  57. filter_iterator& operator= (filter_iterator const&);
  58. };
  59. }}
  60. #ifdef BOOST_FUSION_WORKAROUND_FOR_LWG_2408
  61. namespace std
  62. {
  63. template <typename Category, typename First, typename Last, typename Pred>
  64. struct iterator_traits< ::boost::fusion::filter_iterator<Category, First, Last, Pred> >
  65. { };
  66. }
  67. #endif
  68. #endif