@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



See also

TODO

This page was last modified on 2024-03-19