remove.hpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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_HPP_INCLUDED
  10. #define BOOST_RANGE_ALGORITHM_REMOVE_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
  22. ///
  23. /// range-based version of the remove std algorithm
  24. ///
  25. /// \pre ForwardRange is a model of the ForwardRangeConcept
  26. template< class ForwardRange, class Value >
  27. inline BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type
  28. remove(ForwardRange& rng, const Value& val)
  29. {
  30. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<ForwardRange> ));
  31. return std::remove(boost::begin(rng),boost::end(rng),val);
  32. }
  33. /// \overload
  34. template< class ForwardRange, class Value >
  35. inline BOOST_DEDUCED_TYPENAME range_iterator<const ForwardRange>::type
  36. remove(const ForwardRange& rng, const Value& val)
  37. {
  38. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange> ));
  39. return std::remove(boost::begin(rng),boost::end(rng),val);
  40. }
  41. // range_return overloads
  42. /// \overload
  43. template< range_return_value re, class ForwardRange, class Value >
  44. inline BOOST_DEDUCED_TYPENAME range_return<ForwardRange,re>::type
  45. remove(ForwardRange& rng, const Value& val)
  46. {
  47. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<ForwardRange> ));
  48. return range_return<ForwardRange,re>::pack(
  49. std::remove(boost::begin(rng), boost::end(rng), val),
  50. rng);
  51. }
  52. /// \overload
  53. template< range_return_value re, class ForwardRange, class Value >
  54. inline BOOST_DEDUCED_TYPENAME range_return<const ForwardRange,re>::type
  55. remove(const ForwardRange& rng, const Value& val)
  56. {
  57. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange> ));
  58. return range_return<const ForwardRange,re>::pack(
  59. std::remove(boost::begin(rng), boost::end(rng), val),
  60. rng);
  61. }
  62. } // namespace range
  63. using range::remove;
  64. } // namespace boost
  65. #endif // include guard