find_first_of


Locate a subsequence within a given sequence.

Search the sequence [ first1 , last1 ) for an element that is contained in the set [ first2 , last2 ). Return an iterator for the sequence [ first1 , last1 ) to the first element in the matching set, or last1 if a match is not found.

Library

Standards<ToolKit>

Declaration


#include <algorithm>

template< class ForwardIterator1, class ForwardIterator2 >
ForwardIterator1 find_first_of
  (
  ForwardIterator1 first1,
  ForwardIterator1 last1,
  ForwardIterator2 first2,
  ForwardIterator2 last2
  );

template
  <
  class ForwardIterator1,
  class ForwardIterator2,
  class BinaryPredicate
  >
ForwardIterator1 find_first_of
  (
  ForwardIterator1 first1,
  ForwardIterator1 last1,
  ForwardIterator2 first2,
  ForwardIterator2 last2,
  BinaryPredicate predicate
  );
  

Complexity

At most ( last - first ) * ( last2 - first2 ) applications of predicate will occur.

Example <ospace/osstd/examples/find1st1.cpp>
#include <iostream>
#include <algorithm>

char phrase[ 12 ] = "Texas Fight";
const char vowels[ 11 ] = "AEIOUaeiou";

void
main()
  {
  char* end = find_first_of( phrase, phrase + 12, vowels, vowels + 11 );

  if ( end == phrase + 12 )
    cout << "No vowels found.\n";
  else
    cout << "The first vowel is \"" << *end << "\"\n";

  }

The first vowel is "e"
Example <ospace/osstd/examples/find1st2.cpp>
#include <iostream>
#include <ctype.h>
#include <algorithm>

char phrase[ 10 ] = "Go Big Red";
const char vowels[ 6 ] = "AEIOU";

bool
match_nocase( const char& a, const char& b )
  {
  return toupper( a ) == b;
  }

void
main()
  {
  char* end = find_first_of
    (
    phrase,
    phrase + 12,
    vowels,
    vowels + 6,
    match_nocase
    );

  if ( end == phrase + 12 )
    cout << "No vowels found.\n";
  else
    cout << "The first vowel is \"" << *end << "\"\n";
   }

The first vowel is "o"

Copyright©1994-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only.