replace_if.hpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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_REPLACE_IF_HPP_INCLUDED
  10. #define BOOST_RANGE_ALGORITHM_REPLACE_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 <algorithm>
  16. namespace boost
  17. {
  18. namespace range
  19. {
  20. /// \brief template function replace_if
  21. ///
  22. /// range-based version of the replace_if std algorithm
  23. ///
  24. /// \pre ForwardRange is a model of the ForwardRangeConcept
  25. /// \pre UnaryPredicate is a model of the UnaryPredicateConcept
  26. template< class ForwardRange, class UnaryPredicate, class Value >
  27. inline ForwardRange&
  28. replace_if(ForwardRange& rng, UnaryPredicate pred,
  29. const Value& val)
  30. {
  31. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<ForwardRange> ));
  32. std::replace_if(boost::begin(rng), boost::end(rng), pred, val);
  33. return rng;
  34. }
  35. /// \overload
  36. template< class ForwardRange, class UnaryPredicate, class Value >
  37. inline const ForwardRange&
  38. replace_if(const ForwardRange& rng, UnaryPredicate pred,
  39. const Value& val)
  40. {
  41. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange> ));
  42. std::replace_if(boost::begin(rng), boost::end(rng), pred, val);
  43. return rng;
  44. }
  45. } // namespace range
  46. using range::replace_if;
  47. } // namespace boost
  48. #endif // include guard