namespace cpp {}

C++ lernen, kennen, anwenden

Benutzer-Werkzeuge

Webseiten-Werkzeuge


kennen:lib:count_if

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.


kennen:lib:count_if [2020-06-14 12:58] (aktuell) – angelegt - Externe Bearbeitung 127.0.0.1
Zeile 1: Zeile 1:
 +====== count_if() ======
 +''#include'' [[..:include:algorithm]]
 +
 +<code cpp>
 +difference_type count_if (In first, In last, Pred pred) 
 +difference_type count_if (Exec pol, In first, In last, Pred pred) 
 + 
 +difference_type ranges::count_if (Range r, Pred pred, Proj proj = {}) 
 +difference_type ranges::count_if (In first, In last, Pred pred, Proj proj = {}) 
 +</code>
 + Liefert die Anzahl der Elemente ''e'' des Bereiches [first,last), auf die das Prädikat ''pred(proj(e))'' zutrifft.
 +
 +==== Parameter ====
 +| ''first'' | Anfang des Bereiches |
 +| ''last''  | Ende des Bereiches |
 +| ''pred''  | einstelliges Prädikat|
 +| ''proj''  | einstelliger Funktor (Vorgabe = ''std::identity'') |
 +| ''pol''   | [[..:include:execution|parallele Ausführungsart]] |
 +==== Ergebnis ====
 +Rückgabewert: 
 +Anzahl der Iteratoren ''i'' im Bereich [first,last), 
 +für die ''pred(proj(*i)) != false'' ist.
 +
 +==== Siehe auch ====
 +[[count]].
 +
 +==== Beispiel ====
 +<code cpp count_if.cpp>
 +#include <algorithm>
 +#include <string>
 +#include <iostream>
 +
 +bool ist_Vokal(char c)
 +{
 +  const char vokale[] = "aeiou";
 +  return std::binary_search(vokale, vokale+5, std::tolower(c));
 +}
 +
 +int main()
 +{
 +  std::string s = "Hallo Welt";
 +  std::cout << std::count_if(begin(s), end(s), ist_Vokal) << '\n';
 +}
 +</code>
  

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki