std::find_first_of
Актуально для C++23.
#include <algorithm>
Актуально на 2024-02-18.
Define overload #1
template<class InputIterator, class ForwardIterator> constexpr InputIterator find_first_of(InputIterator first1, InputIterator last1, ForwardIterator first2, ForwardIterator last2);
Ищет в диапазоне [first1, last1], первый, начиная с позиции first1, любой элемент из диапазона [first2, last2].
Вернёт итератор на первый найденный элемент, или last1, если нет совпадений.
Example, possible implementation
Define overload #2
template <class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2> ForwardIterator1 find_first_of(ExecutionPolicy&& exec, ForwardIterator1 first, ForwardIterator1 last, ForwardIterator2 s_first, ForwardIterator2 s_last);
Example, possible implementation
Define overload #3
template<class InputIterator, class ForwardIterator, class BinaryPredicate> constexpr InputIterator find_first_of(InputIterator first1, InputIterator last1, ForwardIterator first2, ForwardIterator last2, BinaryPredicate comp);
Ищет в диапазоне [first1, last1], первый, начиная с позиции first1, любой элемент из диапазона [first2, last2], применяя предикат для сравнения.
Вернёт итератор на первый найденный элемент, или last1, если нет совпадений.
Example, possible implementation
Define overload #4
template <class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class BinaryPredicate> ForwardIterator1 find_first_of(ExecutionPolicy&& exec, ForwardIterator1 first, ForwardIterator1 last, ForwardIterator2 s_first, ForwardIterator2 s_last, BinaryPredicate pred)
Example, possible implementation
Examples
Example 1:
#include <iostream> #include <algorithm> #include <vector> #include <string> int main() { auto f = {'!', '_', '1'}; std::string str = "hel1o_world!"; auto find_it = std::find_first_of(std::begin(str), std::end(str), std::begin(f), std::end(f)); if (find_it != std::end(str)) { std::cout << std::string_view(find_it, std::end(str)) << std::endl; } else { std::cout << "No matches." << std::endl; } return 0; }
1o_world!
Example 2:
#include <iostream> #include <algorithm> #include <vector> #include <string> int main() { auto f = {'!', '_'}; auto pred = [](auto i_el, auto f_el) { return i_el == f_el; }; std::string str = "hello_world!"; auto find_it = std::find_first_of(std::begin(str), std::end(str), std::begin(f), std::end(f), pred); if (find_it != std::end(str)) { std::cout << std::string_view(find_it, std::end(str)) << std::endl; } else { std::cout << "No matches." << std::endl; } return 0; }
_world!
Changelog
C++26
TODOC++23
TODOC++20
TODOC++17
TODOC++14
TODOC++11
TODOSee also
TODO
This page was last modified on 2024-02-18