Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:27:55

0001 /// \file
0002 // Range v3 library
0003 //
0004 //  Copyright Eric Niebler 2014-present
0005 //
0006 //  Use, modification and distribution is subject to the
0007 //  Boost Software License, Version 1.0. (See accompanying
0008 //  file LICENSE_1_0.txt or copy at
0009 //  http://www.boost.org/LICENSE_1_0.txt)
0010 //
0011 // Project home: https://github.com/ericniebler/range-v3
0012 //
0013 #ifndef RANGES_V3_ALGORITHM_REPLACE_IF_HPP
0014 #define RANGES_V3_ALGORITHM_REPLACE_IF_HPP
0015 
0016 #include <meta/meta.hpp>
0017 
0018 #include <range/v3/range_fwd.hpp>
0019 
0020 #include <range/v3/functional/identity.hpp>
0021 #include <range/v3/functional/invoke.hpp>
0022 #include <range/v3/iterator/concepts.hpp>
0023 #include <range/v3/iterator/traits.hpp>
0024 #include <range/v3/range/access.hpp>
0025 #include <range/v3/range/concepts.hpp>
0026 #include <range/v3/range/dangling.hpp>
0027 #include <range/v3/range/traits.hpp>
0028 #include <range/v3/utility/static_const.hpp>
0029 
0030 #include <range/v3/detail/prologue.hpp>
0031 
0032 namespace ranges
0033 {
0034     /// \addtogroup group-algorithms
0035     /// @{
0036     RANGES_FUNC_BEGIN(replace_if)
0037 
0038         /// \brief function template \c replace_if
0039         template(typename I, typename S, typename C, typename T, typename P = identity)(
0040             requires input_iterator<I> AND sentinel_for<S, I> AND
0041                 indirect_unary_predicate<C, projected<I, P>> AND
0042                 indirectly_writable<I, T const &>)
0043         constexpr I RANGES_FUNC(replace_if)(
0044             I first, S last, C pred, T const & new_value, P proj = P{}) //
0045         {
0046             for(; first != last; ++first)
0047                 if(invoke(pred, invoke(proj, *first)))
0048                     *first = new_value;
0049             return first;
0050         }
0051 
0052         /// \overload
0053         template(typename Rng, typename C, typename T, typename P = identity)(
0054             requires input_range<Rng> AND
0055                 indirect_unary_predicate<C, projected<iterator_t<Rng>, P>> AND
0056                 indirectly_writable<iterator_t<Rng>, T const &>)
0057         constexpr borrowed_iterator_t<Rng> RANGES_FUNC(replace_if)(
0058             Rng && rng, C pred, T const & new_value, P proj = P{}) //
0059         {
0060             return (*this)(
0061                 begin(rng), end(rng), std::move(pred), new_value, std::move(proj));
0062         }
0063 
0064     RANGES_FUNC_END(replace_if)
0065 
0066     namespace cpp20
0067     {
0068         using ranges::replace_if;
0069     }
0070     /// @}
0071 } // namespace ranges
0072 
0073 #include <range/v3/detail/epilogue.hpp>
0074 
0075 #endif