Javatpoint Logo
Javatpoint Logo

C++ Algorithm Function find_first_of()

C++ Algorithm find_first_of() function compares the values stored in two containers i.e [first1, last1) and [first2, last2). If an element similar to the one in the range [first2, last2) is found in [first1, last1) then an iterator to that element is returned by the function. In the situations where more than one similar element is present in both the ranges, the iterator to the first similar element is returned. If the case arises where no two elements are common in the range then an iterator to last1 element is returned.

Syntax

Parameter

first1: It is a forward iterator to the first element in the range [first1, last1) where the element itself is included in the range.

last1: It is a forward iterator to the last element in the range [first1, last1) where the element itself is not included in the range.

first2: It is a forward iterator to the first element in the range [first2, last2) where the element itself is included in the range.

last2: It is a forward iterator to the last element in the range [first2, last2) where the element itself is not included in the range.

pred: It is a binary function that accepts two elements as arguments and performs the task designed by the function.

Return value

The function returns an iterator to the first common element of the range [first1, last1) that is also a part of the range [first2,last2).In case no such element is found then the function returns last1 element.

Example 1

Output:

Match 1 is: A
Match 1 is: a

Example 2

Output:

First vowel has been discovered at index 1

Complexity

The complexity of the function is specified by count1*count2. Here countX specifies the distance between the firstX and lastX. The comparison is done until a matching element is found.

Data races

From both the ranges some of the elements are accessed.

Exceptions

The function throws an exception if any of the argument throws one.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA