remove_if.hpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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