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_COPY_IF_HPP
0014 #define RANGES_V3_ALGORITHM_REPLACE_COPY_IF_HPP
0015 
0016 #include <meta/meta.hpp>
0017 
0018 #include <range/v3/range_fwd.hpp>
0019 
0020 #include <range/v3/algorithm/result_types.hpp>
0021 #include <range/v3/functional/identity.hpp>
0022 #include <range/v3/functional/invoke.hpp>
0023 #include <range/v3/iterator/concepts.hpp>
0024 #include <range/v3/iterator/traits.hpp>
0025 #include <range/v3/range/access.hpp>
0026 #include <range/v3/range/concepts.hpp>
0027 #include <range/v3/range/dangling.hpp>
0028 #include <range/v3/range/traits.hpp>
0029 #include <range/v3/utility/static_const.hpp>
0030 
0031 #include <range/v3/detail/prologue.hpp>
0032 
0033 namespace ranges
0034 {
0035     /// \addtogroup group-algorithms
0036     /// @{
0037     template<typename I, typename O>
0038     using replace_copy_if_result = detail::in_out_result<I, O>;
0039 
0040     RANGES_FUNC_BEGIN(replace_copy_if)
0041 
0042         /// \brief function template \c replace_copy_if
0043         template(typename I,
0044                  typename S,
0045                  typename O,
0046                  typename C,
0047                  typename T,
0048                  typename P = identity)(
0049             requires input_iterator<I> AND sentinel_for<S, I> AND
0050                 output_iterator<O, T const &> AND
0051                 indirect_unary_predicate<C, projected<I, P>> AND
0052                 indirectly_copyable<I, O>)
0053         constexpr replace_copy_if_result<I, O> RANGES_FUNC(replace_copy_if)(
0054             I first, S last, O out, C pred, T const & new_value, P proj = {}) //
0055         {
0056             for(; first != last; ++first, ++out)
0057             {
0058                 auto && x = *first;
0059                 if(invoke(pred, invoke(proj, x)))
0060                     *out = new_value;
0061                 else
0062                     *out = (decltype(x) &&)x;
0063             }
0064             return {first, out};
0065         }
0066 
0067         /// \overload
0068         template(typename Rng, typename O, typename C, typename T, typename P = identity)(
0069             requires input_range<Rng> AND output_iterator<O, T const &> AND
0070                 indirect_unary_predicate<C, projected<iterator_t<Rng>, P>> AND
0071                 indirectly_copyable<iterator_t<Rng>, O>)
0072         constexpr replace_copy_if_result<borrowed_iterator_t<Rng>, O> RANGES_FUNC(replace_copy_if)(
0073             Rng && rng, O out, C pred, T const & new_value, P proj = {}) //
0074         {
0075             return (*this)(begin(rng),
0076                            end(rng),
0077                            std::move(out),
0078                            std::move(pred),
0079                            new_value,
0080                            std::move(proj));
0081         }
0082 
0083     RANGES_FUNC_END(replace_copy_if)
0084 
0085     namespace cpp20
0086     {
0087         using ranges::replace_copy_if;
0088         using ranges::replace_copy_if_result;
0089     } // namespace cpp20
0090     /// @}
0091 } // namespace ranges
0092 
0093 #include <range/v3/detail/epilogue.hpp>
0094 
0095 #endif