filter_view.hpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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_SEQUENCE_FILTER_VIEW_HPP)
  7. #define FUSION_SEQUENCE_FILTER_VIEW_HPP
  8. #include <boost/fusion/support/config.hpp>
  9. #include <boost/fusion/support/detail/access.hpp>
  10. #include <boost/fusion/support/sequence_base.hpp>
  11. #include <boost/fusion/support/is_view.hpp>
  12. #include <boost/fusion/view/filter_view/filter_view_iterator.hpp>
  13. #include <boost/fusion/view/filter_view/detail/begin_impl.hpp>
  14. #include <boost/fusion/view/filter_view/detail/end_impl.hpp>
  15. #include <boost/fusion/view/filter_view/detail/size_impl.hpp>
  16. #include <boost/fusion/sequence/intrinsic/begin.hpp>
  17. #include <boost/fusion/sequence/intrinsic/end.hpp>
  18. #include <boost/mpl/bool.hpp>
  19. #include <boost/mpl/eval_if.hpp>
  20. #include <boost/mpl/inherit.hpp>
  21. #include <boost/mpl/identity.hpp>
  22. namespace boost { namespace fusion
  23. {
  24. struct filter_view_tag;
  25. struct forward_traversal_tag;
  26. struct fusion_sequence_tag;
  27. template <typename Sequence, typename Pred>
  28. struct filter_view : sequence_base<filter_view<Sequence, Pred> >
  29. {
  30. typedef filter_view_tag fusion_tag;
  31. typedef fusion_sequence_tag tag; // this gets picked up by MPL
  32. typedef typename
  33. mpl::eval_if<
  34. traits::is_associative<Sequence>
  35. , mpl::inherit2<forward_traversal_tag,associative_tag>
  36. , mpl::identity<forward_traversal_tag>
  37. >::type
  38. category;
  39. typedef mpl::true_ is_view;
  40. typedef typename result_of::begin<Sequence>::type first_type;
  41. typedef typename result_of::end<Sequence>::type last_type;
  42. typedef Pred pred_type;
  43. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  44. filter_view(Sequence& in_seq)
  45. : seq(in_seq)
  46. {}
  47. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  48. first_type first() const { return fusion::begin(seq); }
  49. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  50. last_type last() const { return fusion::end(seq); }
  51. typename mpl::if_<traits::is_view<Sequence>, Sequence, Sequence&>::type seq;
  52. private:
  53. // silence MSVC warning C4512: assignment operator could not be generated
  54. filter_view& operator= (filter_view const&);
  55. };
  56. }}
  57. #endif