std::find_if
Актуально для C++23.
#include <algorithm>
Актуально на 2024-02-17.
Define overload #1
template<class IIter, class Predicate> constexpr IIter find_if(IIter first, IIter last, Predicate pred);
Ищет в заданном диапазоне [first, last] значение удовлетворяющий предикат pred.
Вернёт итератор на первый найденный элемент, или last, если такого элемента не нашлось.
Поиск выполняется последовательным перебором, начиная с позиции "first".
Example, possible implementation
Define overload #2
template <class ExecutionPolicy, class ForwardIterator, class Predicate> ForwardIterator find_if(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, Predicate pred);
Example, possible implementation
Examples
Example 1:
#include <iostream>
#include <string>
#include <algorithm>
#include <cctype>
int main()
{
std::string str = "hello world!";
auto find_it = std::find_if(std::begin(str), std::end(str), [](auto s){ return ::isspace(static_cast<unsigned char>(s)); });
if (find_it != std::end(str))
{
std::cout << "s:" << std::string_view(find_it, std::end(str)) << std::endl;
}
else
{
std::cout << "Нет пробелов!" << std::endl;
}
return 0;
}
s: world!
Changelog
See also
TODO
This page was last modified on 2024-02-17