erase.hpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. template< class Container >
  50. inline Container& unique_erase( Container& on)
  51. {
  52. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<Container> ));
  53. on.erase(
  54. std::unique(boost::begin(on), boost::end(on)),
  55. boost::end(on));
  56. return on;
  57. }
  58. template< class Container, class Pred >
  59. inline Container& unique_erase( Container& on, Pred pred )
  60. {
  61. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<Container> ));
  62. on.erase(
  63. std::unique(boost::begin(on), boost::end(on), pred),
  64. boost::end(on));
  65. return on;
  66. }
  67. } // namespace range
  68. using range::erase;
  69. using range::remove_erase;
  70. using range::remove_erase_if;
  71. using range::unique_erase;
  72. } // namespace boost
  73. #endif // include guard