replace.hpp 1.5 KB

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