stl:algorithm:find_first_of

C++ Reference

find_first_of

Syntax:

    #include <algorithm>
    iterator find_first_of( iterator start, iterator end, iterator find_start, iterator find_end );
    iterator find_first_of( iterator start, iterator end, iterator find_start, iterator find_end, BinPred bp );

The find_first_of() function searches for the first occurence of any element between find_start and find_end. The data that are searched are those between start and end.

If any element between find_start and find_end is found, an iterator pointing to that element is returned. Otherwise, an iterator pointing to end is returned.

For example, the following code searches for a 9, 4, or 7 in an array of integers:

   int nums[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
   int* result;
   int start = 0;
   int end = 10;
 
   int targets[] = { 9, 4, 7 };
   result = find_first_of( nums + start, nums + end, targets + 0, targets + 2 );
   if( *result == nums[end] ) {
     cout << "Did not find any of { 9, 4, 7 }" << endl;
   } else {
     cout << "Found a matching target: " << *result << endl;
   }

Related Topics: adjacent_find, find, find_end, find_if, strpbrk