@specsoftdev live:.cid.8e17e9b93cabb607 specsoftdev@gmail.com
std::replace_copy
Актуально для C++23.

#include <algorithm>
Актуально на 2024-03-19.



Define overload #1
template<class InputIter, class OutputIter, class T>
constexpr OutputIter
replace_copy(InputIter first, InputIter last, OutputIter result,
             const T& old_value, const T& new_value);

Копирует с заменой элементы из диапазона [first, last] в result.
Элементы эквивалентные "old_value" будут заменены на "new_value".
Вернёт Output итератор увеличенный на количество скопированных элементов.
Элементы сравниваются с помощью оператора "==".
Example, possible implementation
Define overload #2
template<class ExecutionPolicy, class ForwardIter1,
         class ForwardIter2, class T>
ForwardIter2
replace_copy(ExecutionPolicy&& exec, ForwardIter1 first, ForwardIter1 last,
             ForwardIter2 result, const T& old_value, const T& new_value);

TODO
Example, possible implementation




Examples


Example 1:
#include <iostream>
#include <algorithm>
#include <string>
#include <string_view>

int main()
{
    using namespace std;
    using namespace std::string_literals;

    auto s = "hello world!"sv;

    std::string result;
    result.resize(s.size());

    replace_copy(std::begin(s), std::end(s), std::begin(result), 'h', 'H');
    std::cout << result << std::endl;
    return 0;
}

Hello world!



Changelog

C++26
TODO
C++23
TODO
C++20
TODO
C++17
TODO
C++14
TODO
C++11
TODO


See also

TODO

This page was last modified on 2024-03-19