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