Namespaces
Variants
Views
Actions

std::find_first_of

From cppreference.com
< cpp‎ | algorithm
Revision as of 05:09, 31 January 2012 by Mankarse (Talk | contribs)

Template:cpp/algorithm/sidebar Template:ddcl list begin <tr class="t-dsc-header">

<td>
Defined in header <algorithm>
</td>

<td></td> <td></td> </tr> <tr class="t-dcl ">

<td >
template< class ForwardIterator1, class ForwardIterator2 >

ForwardIterator1 find_first_of( ForwardIterator1 first, ForwardIterator1 last,

                                ForwardIterator2 s_first, ForwardIterator2 s_last );
</td>

<td > (1) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td >
template< class ForwardIterator1, class ForwardIterator2, class BinaryPredicate >

ForwardIterator1 find_first_of( ForwardIterator1 first, ForwardIterator1 last,

                                ForwardIterator2 s_first, ForwardIterator2 s_last, BinaryPredicate p );
</td>

<td > (2) </td> <td class="t-dcl-nopad"> </td> </tr> Template:ddcl list end

Searches the range [first, last) for any of the elements in the range [s_first, s_last). The first version uses operator== to compare the elements, the second version uses the given binary predicate p.

Contents

Parameters

first, last - the range of elements to examine
s_first, s_last - the range of elements to search for
p - binary predicate which returns ​true if the elements should be treated as equal.

The signature of the predicate function should be equivalent to the following:

 bool pred(const Type1 &a, const Type2 &b);

While the signature does not need to have const &, the function must not modify the objects passed to it and must be able to accept all values of type (possibly const) Type1 and Type2 regardless of value category (thus, Type1 & is not allowed, nor is Type1 unless for Type1 a move is equivalent to a copy(since C++11)).
The types Type1 and Type2 must be such that objects of types ForwardIterator1 and ForwardIterator2 can be dereferenced and then implicitly converted to Type1 and Type2 respectively. ​

Return value

iterator to the first element in the range [first, last) that is equal to an element from the range [s_first; s_last). If no such element is found, last is returned.

Complexity

does at most (S*N) comparisons where Template:cpp and Template:cpp.

Equivalent function

Template:eq fun cpp

Example

Template:example cpp

See also

Template:cpp/algorithm/dcl list find