namespace cpp {}

C++ lernen, kennen, anwenden

Benutzer-Werkzeuge

Webseiten-Werkzeuge


Action disabled: source
kennen:lib:for_each

for_each()

#include <algorithm>

Function for_each (In first, In last, Function f) 
Function for_each (Exec pol, In first, In last, Function f) 
 
[last, f] = ranges::for_each(Range r, Function f, Proj proj = {})
[last, f] = ranges::for_each(In first, In last, Function f, Proj proj = {})

Wendet f(proj(e)) auf jedes Element e des Bereiches [first,last) an.

Parameter

first Anfang des Bereiches
last Ende des Bereiches
f einstellige Funktion oder Funktor
proj einstelliger Funktor (Vorgabe = std::identity)
pol parallele Ausführungsart

Ergebnis

Rückgabewert: die Funktion bzw. das (möglicherweise veränderte) Funktionsobjekt f bzw. als Struktur mit Elementen namens in, fun.

Siehe auch

Beispiel

for_each.cpp
#include <algorithm>
#include <iostream>
 
int main()
{
  int arr[] = { 1, 2, 3, 4, 5 };
  std::for_each(arr, ar+5), [](int x) { std::cout << x << ' '; });
}
kennen/lib/for_each.txt · Zuletzt geändert: 2023-10-14 12:26 von rrichter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki