remove_if.hpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright Neil Groves 2009. Use, modification and
  2. // distribution is subject to the Boost Software License, Version
  3. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. //
  6. //
  7. // For more information, see http://www.boost.org/libs/range/
  8. //
  9. #ifndef BOOST_RANGE_ALGORITHM_REMOVE_IF_HPP_INCLUDED
  10. #define BOOST_RANGE_ALGORITHM_REMOVE_IF_HPP_INCLUDED
  11. #include <boost/concept_check.hpp>
  12. #include <boost/range/begin.hpp>
  13. #include <boost/range/end.hpp>
  14. #include <boost/range/concepts.hpp>
  15. #include <boost/range/detail/range_return.hpp>
  16. #include <algorithm>
  17. namespace boost
  18. {
  19. namespace range
  20. {
  21. /// \brief template function remove_if
  22. ///
  23. /// range-based version of the remove_if std algorithm
  24. ///
  25. /// \pre ForwardRange is a model of the ForwardRangeConcept
  26. /// \pre UnaryPredicate is a model of the UnaryPredicateConcept
  27. template< class ForwardRange, class UnaryPredicate >
  28. inline BOOST_DEDUCED_TYPENAME boost::range_iterator<ForwardRange>::type
  29. remove_if(ForwardRange& rng, UnaryPredicate pred)
  30. {
  31. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<ForwardRange> ));
  32. return std::remove_if(boost::begin(rng), boost::end(rng), pred);
  33. }
  34. /// \overload
  35. template< class ForwardRange, class UnaryPredicate >
  36. inline BOOST_DEDUCED_TYPENAME boost::range_iterator<const ForwardRange>::type
  37. remove_if(const ForwardRange& rng, UnaryPredicate pred)
  38. {
  39. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange> ));
  40. return std::remove_if(boost::begin(rng), boost::end(rng), pred);
  41. }
  42. // range_return overloads
  43. /// \overload
  44. template< range_return_value re, class ForwardRange, class UnaryPredicate >
  45. inline BOOST_DEDUCED_TYPENAME range_return<ForwardRange,re>::type
  46. remove_if(ForwardRange& rng, UnaryPredicate pred)
  47. {
  48. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<ForwardRange> ));
  49. return range_return<ForwardRange,re>::pack(
  50. std::remove_if(boost::begin(rng), boost::end(rng), pred),
  51. rng);
  52. }
  53. /// \overload
  54. template< range_return_value re, class ForwardRange, class UnaryPredicate >
  55. inline BOOST_DEDUCED_TYPENAME range_return<const ForwardRange,re>::type
  56. remove_if(const ForwardRange& rng, UnaryPredicate pred)
  57. {
  58. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange> ));
  59. return range_return<const ForwardRange,re>::pack(
  60. std::remove_if(boost::begin(rng), boost::end(rng), pred),
  61. rng);
  62. }
  63. } // namespace range
  64. using range::remove_if;
  65. } // namespace boost
  66. #endif // include guard