remove_if.hpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #ifndef BOOST_MPL_REMOVE_IF_HPP_INCLUDED
  2. #define BOOST_MPL_REMOVE_IF_HPP_INCLUDED
  3. // Copyright Aleksey Gurtovoy 2000-2004
  4. // Copyright David Abrahams 2003-2004
  5. //
  6. // Distributed under the Boost Software License, Version 1.0.
  7. // (See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. // See http://www.boost.org/libs/mpl for documentation.
  11. // $Id$
  12. // $Date$
  13. // $Revision$
  14. #include <boost/mpl/fold.hpp>
  15. #include <boost/mpl/reverse_fold.hpp>
  16. #include <boost/mpl/eval_if.hpp>
  17. #include <boost/mpl/identity.hpp>
  18. #include <boost/mpl/protect.hpp>
  19. #include <boost/mpl/lambda.hpp>
  20. #include <boost/mpl/apply.hpp>
  21. #include <boost/mpl/aux_/inserter_algorithm.hpp>
  22. namespace boost { namespace mpl {
  23. namespace aux {
  24. template< typename Pred, typename InsertOp > struct remove_if_helper
  25. {
  26. template< typename Sequence, typename U > struct apply
  27. {
  28. typedef typename eval_if<
  29. typename apply1<Pred,U>::type
  30. , identity<Sequence>
  31. , apply2<InsertOp,Sequence,U>
  32. >::type type;
  33. };
  34. };
  35. template<
  36. typename Sequence
  37. , typename Predicate
  38. , typename Inserter
  39. >
  40. struct remove_if_impl
  41. : fold<
  42. Sequence
  43. , typename Inserter::state
  44. , protect< aux::remove_if_helper<
  45. typename lambda<Predicate>::type
  46. , typename Inserter::operation
  47. > >
  48. >
  49. {
  50. };
  51. template<
  52. typename Sequence
  53. , typename Predicate
  54. , typename Inserter
  55. >
  56. struct reverse_remove_if_impl
  57. : reverse_fold<
  58. Sequence
  59. , typename Inserter::state
  60. , protect< aux::remove_if_helper<
  61. typename lambda<Predicate>::type
  62. , typename Inserter::operation
  63. > >
  64. >
  65. {
  66. };
  67. } // namespace aux
  68. BOOST_MPL_AUX_INSERTER_ALGORITHM_DEF(3, remove_if)
  69. }}
  70. #endif // BOOST_MPL_REMOVE_IF_HPP_INCLUDED