#include
<algorithm>
In find_if (In first, In last, Pred pred) In find_if (Exec pol, In first, In last, Pred pred) In ranges::find_if (Range r, Pred pred, Proj proj = {}) In ranges::find_if (In first, In last, Pred pred, Proj proj = {})
Liefert einen Iterator i auf das erste Element des Bereiches [first,last), auf den das Prädikat pred(proj(*i))
zutrifft.
first | Anfang des Bereiches |
last | Ende des Bereiches |
pred | einstelliges Prädikat |
proj | einstelliger Funktor (Vorgabe = std::identity ) |
pol | parallele Ausführungsart |
Rückgabewert: Iterator i
auf erstes Element mit pred(proj(*i)) != false
.
Wurde kein Element gefunden, wird last
geliefert.
#include <algorithm> #include <iostream> bool ist_vokal(char c) { return c=='a' || c=='e' || c=='i' || c=='o' || c=='u'; } int main() { const char str[] = "Hallo Welt"; const char *pos = std::find_if(str, str+10, ist_vokal); if (pos != end(str)) { std::cout << pos << '\n'; } }