Horizon
replace_if.hpp
Go to the documentation of this file.
1 // Range v3 library
3 //
4 // Copyright Eric Niebler 2014-present
5 //
6 // Use, modification and distribution is subject to the
7 // Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
10 //
11 // Project home: https://github.com/ericniebler/range-v3
12 //
13 #ifndef RANGES_V3_ALGORITHM_REPLACE_IF_HPP
14 #define RANGES_V3_ALGORITHM_REPLACE_IF_HPP
15 
16 #include <meta/meta.hpp>
17 
18 #include <range/v3/range_fwd.hpp>
19 
28 #include <range/v3/utility/static_const.hpp>
29 
30 #include <range/v3/detail/prologue.hpp>
31 
32 namespace ranges
33 {
36  RANGES_FUNC_BEGIN(replace_if)
37 
38 
39  template(typename I, typename S, typename C, typename T, typename P = identity)(
40  requires input_iterator<I> AND sentinel_for<S, I> AND
41  indirect_unary_predicate<C, projected<I, P>> AND
42  indirectly_writable<I, T const &>)
43  constexpr I RANGES_FUNC(replace_if)(
44  I first, S last, C pred, T const & new_value, P proj = P{}) //
45  {
46  for(; first != last; ++first)
47  if(invoke(pred, invoke(proj, *first)))
48  *first = new_value;
49  return first;
50  }
51 
53  template(typename Rng, typename C, typename T, typename P = identity)(
54  requires input_range<Rng> AND
55  indirect_unary_predicate<C, projected<iterator_t<Rng>, P>> AND
57  constexpr borrowed_iterator_t<Rng> RANGES_FUNC(replace_if)(
58  Rng && rng, C pred, T const & new_value, P proj = P{}) //
59  {
60  return (*this)(
61  begin(rng), end(rng), std::move(pred), new_value, std::move(proj));
62  }
63 
64  RANGES_FUNC_END(replace_if)
65 
66  namespace cpp20
67  {
68  using ranges::replace_if;
69  }
71 } // namespace ranges
72 
73 #include <range/v3/detail/epilogue.hpp>
74 
75 #endif
template(typename Rng, typename C, typename T, typename P=identity)(requires input_range< Rng > AND indirect_unary_predicate< C
This is an overloaded member function, provided for convenience. It differs from the above function o...
CPP_concept sentinel_for
\concept sentinel_for
Definition: concepts.hpp:306
CPP_concept indirect_unary_predicate
\concept indirect_unary_predicate
Definition: concepts.hpp:632
CPP_concept input_iterator
\concept input_iterator
Definition: concepts.hpp:362
CPP_concept indirectly_writable
\concept indirectly_writable
Definition: concepts.hpp:169
decltype(begin(declval(Rng &))) iterator_t
Definition: access.hpp:698
typename Fn::template invoke< Args... > invoke
Evaluate the invocable Fn with the arguments Args.
Definition: meta.hpp:541
front< Pair > first
Retrieve the first element of the pair Pair.
Definition: meta.hpp:2251
Tiny meta-programming library.
Definition: identity.hpp:25