Name
find_first_of function template — Searches for any one of a sequence of values
Synopsis
template<typename FwdIter1, typename FwdIter2> FwdIter1 find_first_of(FwdIter1 first1, FwdIter1 last1, FwdIter2 first2, FwdIter2 last2); template<typename FwdIter1, typename FwdIter2, typename BinaryPredicate> FwdIter1 find_first_of(FwdIter1 first1, FwdIter1 last1, FwdIter2 first2, FwdIter2 last2, BinaryPredicate pred);
The find_first_of
function
template searches the range [first1
, last1
) for any one of the items in
[first2
, last2
). If it finds a matching item, it
returns an iterator that points to the matching item, in the range
[first1
, last1
). It returns last1
if no matching item is found. Figure 13-6 shows an
example.
The first form compares items with the ==
operator. The second form calls
pred(*iter1
, *iter2)
.
Technical Notes
Let length1 = last1 - first1 and length2 = last2 - first2.
The find_first_of
function
template returns first1 +
n where n is the smallest value in the range [0,
length1) such that *(first1 + n) == (first2 + m) for some m in the range [0, length2). It returns last1 if no such n and m can be found.
Complexity: at most length1 × length2 comparisons are performed.
See Also
Get C++ In a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.