STD Find, STD Find If, STD Find If Not - Cppreference
STD Find, STD Find If, STD Find If Not - Cppreference
(1)
(2)
(3)
(sinc e C++11)
Returns the rs t element in the range [first, last)that s atis es s pecic criteria:
1) finds earches for an element equal to value
2) find_ifs earches for an element for which predicate preturns true
3) find_if_nots earches for an element for which predicate qreturns false
Parameters
first, last - the range of elements to examine
value - value to compare the elements to
p - unary predicate which returns true for the required element.
The s ignature of the predicate function s hould be equivalent to the following:
bool pred(const Type &a);
The s ignature does not need to have const &, but the function mus t not modify the
objects pas s ed to it.
The type Type mus t be s uch that an object of type InputIt can be dereferenced
and then implicitly converted to Type.
q - unary predicate which returns false for the required element.
The s ignature of the predicate function s hould be equivalent to the following:
bool pred(const Type &a);
The s ignature does not need to have const &, but the function mus t not modify the
objects pas s ed to it.
The type Type mus t be s uch that an object of type InputIt can be dereferenced
and then implicitly converted to Type.
Type requirements
-
Return value
Iterator to the rs t element s atis fying the condition or lastif no s uch element is found.
Complexity
At mos t last- firstapplications of the predicate
Possible implementation
First version
Example
The following example nds an integer in a vector of integers .
Run this code
#include <iostream>
#include <algorithm>
#include <vector>
#include <iterator>
int main()
{
int n1 = 3;
int n2 = 5;
Output:
v contains: 3
v does not contain: 5
See also
adjacent_find
find_end
find_first_of
mismatch
search
std::experimental::parallel::find(parallelism TS )
std::experimental::parallel::find_if(parallelism TS )