std::replace_if
Актуально для C++23.
#include <algorithm>
Актуально на 2024-03-20.
Define overload #1
template<class ForwardIterator, class Predicate, class T> constexpr void replace_if(ForwardIterator first, ForwardIterator last, Predicate pred, const T& new_value);
Заменяет элементы в диапазоне [first, last] для которых унарный предикат "pred" вернёт true на "new_value".
Элементы сравниваются с помощью оператора "==".
Example, possible implementation
Define overload #2
template<class ExecutionPolicy, class ForwardIterator, class Predicate, class T> void replace_if(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, Predicate pred, 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_if(std::begin(s), std::end(s), [](auto ch){ return ch == 'h'; } , 'H'); std::cout << s << std::endl; return 0; }
Hello world!
Changelog
C++26
TODOC++23
TODOC++20
TODOC++17
TODOC++14
TODOC++11
TODOSee also
TODO
This page was last modified on 2024-03-20