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

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



Define overload #1
template<class ForwardIterator, class T>
constexpr void
replace(ForwardIterator first, ForwardIterator last,
        const T& old_value, const T& new_value);

Заменяет элементы в диапазоне [first, last] эквивалентные old_value на new_value.
Элементы сравниваются с помощью оператора "==".
Example, possible implementation
Define overload #2
template<class ExecutionPolicy, class ForwardIterator, class T>
void replace(ExecutionPolicy&& exec, orwardIterator first,
             ForwardIterator last, const T& old_value, const T& new_value);

TODO
Example, possible implementation


Examples


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

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

    auto s = "hello world!"s;

    replace(std::begin(s), std::end(s), 'h', 'H');
    std::cout << s << 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-20