erase.hpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Boost.Range library
  2. //
  3. // Copyright Neil Groves 2009. Use, modification and
  4. // distribution is subject to the Boost Software License, Version
  5. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. // For more information, see http://www.boost.org/libs/range/
  9. //
  10. #ifndef BOOST_RANGE_ALGORITHM_EXT_ERASE_HPP_INCLUDED
  11. #define BOOST_RANGE_ALGORITHM_EXT_ERASE_HPP_INCLUDED
  12. #include <boost/range/config.hpp>
  13. #include <boost/range/concepts.hpp>
  14. #include <boost/range/difference_type.hpp>
  15. #include <boost/range/iterator_range_core.hpp>
  16. #include <boost/range/begin.hpp>
  17. #include <boost/range/end.hpp>
  18. #include <boost/assert.hpp>
  19. namespace boost
  20. {
  21. namespace range
  22. {
  23. template< class Container >
  24. inline Container& erase( Container& on,
  25. iterator_range<BOOST_DEDUCED_TYPENAME Container::iterator> to_erase )
  26. {
  27. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<Container> ));
  28. on.erase( boost::begin(to_erase), boost::end(to_erase) );
  29. return on;
  30. }
  31. template< class Container, class T >
  32. inline Container& remove_erase( Container& on, const T& val )
  33. {
  34. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<Container> ));
  35. on.erase(
  36. std::remove(boost::begin(on), boost::end(on), val),
  37. boost::end(on));
  38. return on;
  39. }
  40. template< class Container, class Pred >
  41. inline Container& remove_erase_if( Container& on, Pred pred )
  42. {
  43. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<Container> ));
  44. on.erase(
  45. std::remove_if(boost::begin(on), boost::end(on), pred),
  46. boost::end(on));
  47. return on;
  48. }
  49. } // namespace range
  50. using range::erase;
  51. using range::remove_erase;
  52. using range::remove_erase_if;
  53. } // namespace boost
  54. #endif // include guard