/// \file // Range v3 library // // Copyright Eric Niebler 2014-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_ALGORITHM_REPLACE_COPY_HPP #define RANGES_V3_ALGORITHM_REPLACE_COPY_HPP #include #include #include #include #include #include #include #include #include #include #include #include namespace ranges { /// \addtogroup group-algorithms /// @{ template using replace_copy_result = detail::in_out_result; RANGES_BEGIN_NIEBLOID(replace_copy) /// \brief function template \c replace_copy template auto RANGES_FUN_NIEBLOID(replace_copy)(I first, S last, O out, T1 const & old_value, T2 const & new_value, P proj = {}) // ->CPP_ret(replace_copy_result)( // requires input_iterator && sentinel_for && output_iterator && indirectly_copyable && indirect_relation, T1 const *>) { for(; first != last; ++first, ++out) { auto && x = *first; if(invoke(proj, x) == old_value) *out = new_value; else *out = (decltype(x) &&)x; } return {first, out}; } /// \overload template auto RANGES_FUN_NIEBLOID(replace_copy)( Rng && rng, O out, T1 const & old_value, T2 const & new_value, P proj = {}) // ->CPP_ret(replace_copy_result, O>)( // requires input_range && output_iterator && indirectly_copyable, O> && indirect_relation, P>, T1 const *>) { return (*this)(begin(rng), end(rng), std::move(out), old_value, new_value, std::move(proj)); } RANGES_END_NIEBLOID(replace_copy) namespace cpp20 { using ranges::replace_copy; using ranges::replace_copy_result; } // namespace cpp20 /// @} } // namespace ranges #endif // include guard