Previous fileTop of DocumentContentsIndex pageNext file
Apache C++ Standard Library Reference Guide

find_first_of()

Library:  Algorithms


Function

Local Index

No Entries

Summary

Algorithm that finds the first occurrence of any value from one sequence in another sequence

Synopsis

#include <algorithm>

namespace std {
  template <class ForwardIterator1, class ForwardIterator2>
  ForwardIterator1 find_first_of (ForwardIterator1 start1,
                                  ForwardIterator1 finish1,
                                  ForwardIterator2 start2,
                                  ForwardIterator2 finish2);

  template <class ForwardIterator1, class ForwardIterator2,
            class BinaryPredicate>
  ForwardIterator1 find_first_of (ForwardIterator1 start1,
                                  ForwardIterator1 finish1,
                                  ForwardIterator2 start2,
                                  ForwardIterator2 finish2,
                                  BinaryPredicate binary_pred);
}

Description

The find_first_of() algorithm finds the first occurrence of a value from a sequence, specified by start2, finish2, in a sequence specified by start1, finish1. The algorithm returns an iterator in the range [start1, finish1) that points to the first matching element. If the first sequence [start1, finish1) does not contain any of the values in the second sequence, find_first_of() returns finish1.

In other words, find_first_of() returns the first iterator i in [start1, finish1)such that for some iterator j in the range [start2, finish2), the following conditions hold:

Or find_first_of() returns finish1 if no such iterator is found.

Two versions of the algorithm exist. The first uses the equality operator as the default binary predicate, and the second allows you to specify a binary predicate.

Complexity

At most (finish1 - start1)*(finish2 - start2) applications of the corresponding predicate are done.

Example

See Also

Algorithms, adjacent_find(), find(), find_if(), find_end()

Standards Conformance

ISO/IEC 14882:1998 -- International Standard for Information Systems -- Programming Language C++, Section 25.1.4



Previous fileTop of DocumentContentsIndex pageNext file