namespace cpp {}

C++ lernen, kennen, anwenden

Benutzer-Werkzeuge

Webseiten-Werkzeuge


kennen:include:algorithm

<algorithm>

Typ-parametrisierte Algorithmen:

Warnung:​ Die "​Kopfzeilen"​ der aufgeführten Algorithmen sind absichtlich kein korrektes C++. Für syntaktisch korrekte Dokumentation sei auf https://​en.cppreference.com/w/cpp/algorithm und https://​en.cppreference.com/w/cpp/algorithm/ranges verwiesen.

Die Einleitung template <...> wurde der Übersichtlichkeit halber bei allen Schablonen weggelassen. Die Iterator-Kategorien Out, In, For, Bi und Ran zeigen an, welche Operationen auf den Bereichen erforderlich sind. Mit Binary und Pred werden Funktionen, Funktionsobjekte und Lambdaausdrücke bezeichnet, die boolesche Rückgabewerte liefern.

Erweiterungen in C++17: Parallele Algorithmen besitzen einen <execution>-Policy-Parameter, hier durch Exec pol gekennzeichnet.

Erweiterungen in C++20: Als Range werden Ausdrücke r bezeichnet, auf die std::ranges::begin(r) und std::ranges::end(r) angewendet werden kann. Projektionen proj(e)1) sind Funktionen, Funktionsobjekte, Lambdaausdrücke oder Adressen wie &Person::name von Bestandteilen eines zusammengesetzten Objekts, die auf ein Element e eines Bereichs r angewendet werden können. Die Standardvorgabe std::identity{} liefert e selbst. Steht an Stelle eines Ergebnistyps ​[x,​y] =,​ liefert der Algorithmus eine zusammengesetzte Struktur, die mittels eines "​structured bindings"​ zerlegt werden kann:

auto [x,y] = f(...);
 
auto result = f(...);
std::cout << result.name1 << ' ' << result.name2; 

Alternativ kann auf die Bestandteile der Rückgabestruktur per Namen zugegriffen werden. Dazu muss man allerdings deren Namen kennen. Diese werden in der Beschreibung der Algorithmen aufgeführt.

Nichtmodifizierende Algorithmen

Ausführen und Zählen

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 = {})

Beschreibung: Wendet f(proj(e)) auf jedes Element e des Bereiches [first,last) an. Obwohl der Algorithmus die Elemente nicht verändert, ist es dem Funktions(objekt)aufruf f(proj(e)) ausdrücklich erlaubt.

difference_type count (In first, In last, T wert) 
difference_type count (Exec pol, In first, In last, T wert) 
 
difference_type ranges::count (Range r, T wert, Proj proj = {}) 
difference_type ranges::count (In first, In last, T wert, Proj proj = {}) 

Beschreibung: Liefert die Anzahl der Elemente des Bereiches [first,last) mit proj(wert).

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 = {}) 

Beschreibung: Liefert die Anzahl der Elemente e des Bereiches [first,last), auf die das Prädikat pred(proj(e)) zutrifft.

Prädikatenlogik

bool all_of (In first, In last, Pred pred)
bool all_of (Exec pol, In first, In last, Pred pred)
 
bool ranges::all_of (Range r, Pred pred, Proj proj = {})
bool ranges::all_of (In first, In last, Pred pred, Proj proj = {})

Beschreibung: Prüft, ob alle Elemente e des Bereiches [first,last) das Prädikat pred(proj(e)) erfüllen. Bei leerem Bereich liefert die Funktion true.

bool any_of (In first, In last, Pred pred) 
bool any_of (Exec pol, In first, In last, Pred pred) 
 
bool ranges::any_of (Range r, Pred pred, Proj proj = {})
bool ranges::any_of (In first, In last, Pred pred, Proj proj = {})

Beschreibung: Prüft, ob irgendein Element e des Bereiches [first,last) das Prädikat pred(proj(e)) erfüllt. Bei leerem Bereich liefert die Funktion false.

bool none_of (In first, In last, Pred pred) 
bool none_of (Exec pol, In first, In last, Pred pred) 
 
bool ranges::none_of (Range r, Pred pred, Proj proj = {})
bool ranges::none_of (In first, In last, Pred pred, Proj proj = {})

Beschreibung: Prüft, ob kein Element e des Bereiches [first,last) das Prädikat pred(proj(e)) erfüllt. Bei leerem Bereich liefert die Funktion true.

Suchen

In find (In first, In last, T wert) 
In find (Exec pol, In first, In last, T wert) 
 
In ranges::find (Range r, T wert, Proj proj = {}) 
In ranges::find (In first, In last, T wert, Proj proj = {}) 

Beschreibung: Liefert einen Iterator i auf das erste Element des Bereiches [first,last) mit proj(*i) == wert.

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 = {}) 

Beschreibung: Liefert einen Iterator i auf das erste Element des Bereiches [first,last), auf den das Prädikat pred(proj(*i)) zutrifft.

In find_if_not (In first, In last, Pred pred) 
In find_if_not (Exec pol, In first, In last, Pred pred) 
 
In ranges::find_if_not (Range r, Pred pred, Proj proj = {}) 
In ranges::find_if_not (In first, In last, Pred pred, Proj proj = {}) 

Beschreibung: Liefert einen Iterator i auf das erste Element des Bereiches [first,last), auf den das Prädikat pred(proj(*i)) nicht zutrifft.

For find_first_of (For first, For last, For2 first2, For2 last2) 
For find_first_of (For first, For last, For2 first2, For2 last2, Binary pred) 
For find_first_of (Exec pol, For first, For last, For2 first2, For2 last2) 
For find_first_of (Exec pol, For first, For last, For2 first2, For2 last2, Binary pred) 
 
For ranges::find_first_of (Range1 r1, Range2 r2, Binary pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) 
For ranges::find_first_of (For first, For last, For2 first2, For2 last2, Binary pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) 

Beschreibung: Liefert einen Iterator i auf das erste Element x des Bereiches [first,last), das mit einem Element y des Bereiches [first2,last2) übereinstimmt bzw. für welches pred(proj1(x), proj2(y)) zutrifft.

For search (For first, For last, For2 first2, For2 last2) 
For search (For first, For last, For2 first2, For2 last2, Binary pred) 
For search (Exec pol, For first, For last, For2 first2, For2 last2) 
For search (Exec pol, For first, For last, For2 first2, For2 last2, Binary pred) 
 
Range ranges::search (Range1 r1, Range2 r2, Binary pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) 
Range ranges::search (For first, For last, For2 first2, For2 last2, Binary pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) 
 
For search (For first, For last, Searcher searcher) // C++17

Beschreibung: Sucht den Anfang eines Teilbereiches (den Teilbereich) aus [first,last), der mit [first2,last2) übereinstimmt, das Prädikat pred(proj1(x),proj2(y)) erfüllt bzw. dem Muster eines Sucher-Objekts entspricht.

For search_n (For first, For last, Size n, T wert) 
For search_n (For first, For last, Size n, T wert, Binary pred) 
For search_n (Exec pol, For first, For last, Size n, T wert) 
For search_n (Exec pol, For first, For last, Size n, T wert, Binary pred) 
 
Range ranges::search_n (Range r, Size n, T wert, Binary pred = {}, Proj proj = {}) 
Range ranges::search_n (For first, For last, Size n, T wert, Binary pred = {}, Proj proj = {}) 

Beschreibung: Sucht den Anfang eines Teilbereiches (den Teilbereich) aus [first,last), der n gleiche Werte hat bzw. auf den n mal pred(proj(x),wert) zutrifft.

For find_end (For first, For last, For2 first2, For2 last2) 
For find_end (For first, For last, For2 first2, For2 last2, Binary pred) 
For find_end (Exec pol, For first, For last, For2 first2, For2 last2) 
For find_end (Exec pol, For first, For last, For2 first2, For2 last2, Binary pred) 
 
Range ranges::find_end (Range1 r1, Range2 r2, Binary pred = {}, Proj1 proj1, Proj2 proj2) 
Range ranges::find_end (For first, For last, For2 first2, For2 last2, Binary pred = {}, Proj1 proj1, Proj2 proj2) 

Beschreibung: Findet den letzten Teilbereich aus [first,last), der mit [first2,last2) übereinstimmt bzw. für dessen Elemente x das Prädikat pred(proj1(x), proj2(y)) mit den entsprechenden Elementen y aus [first2,last2) zutrifft.

For adjacent_find (For first, For last) 
For adjacent_find (For first, For last, Binary pred) 
For adjacent_find (Exec pol, For first, For last) 
For adjacent_find (Exec pol, For first, For last, Binary pred) 
 
For ranges::adjacent_find (Range r, Binary pred = {}, Proj = {}) 
For ranges::adjacent_find (For first, For last, Binary pred = {}, Proj = {}) 

Beschreibung: Liefert einen Iterator i auf das erste Element des Bereiches [first,last), das mit seinem Nachfolger übereinstimmt bzw. mit seinem Nachfolger das Prädikat pred(proj(*i),proj(*(i+1))) erfüllt.

Binärsuche

bool binary_search (For first, For last, T wert) 
bool binary_search (For first, For last, T wert, Binary comp) 
 
bool ranges::binary_search (Range r, T wert, Binary comp = {}, Proj proj = {}) 
bool ranges::binary_search (For first, For last, T wert, Binary comp = {}, Proj proj = {}) 

Beschreibung: Prüft, ob wert (als Projektion) in der aufsteigend geordneten Folge [first,last) enthalten ist.

For lower_bound (For first, For last, T wert) 
For lower_bound (For first, For last, T wert, Binary comp) 
 
For ranges::lower_bound (Range r, T wert, Binary comp = {}, Proj proj = {}) 
For ranges::lower_bound (For first, For last, T wert, Binary comp = {}, Proj proj = {}) 

Beschreibung: Bestimmt die erste Position, an der ein Element eingefügt werden kann, ohne die aufsteigende Ordnung der Folge [first,last) zu zerstören.

For upper_bound (For first, For last, T wert) 
For upper_bound (For first, For last, T wert, Binary comp) 
 
For ranges::upper_bound (Range r, T wert, Binary comp = {}, Proj proj = {}) 
For ranges::upper_bound (For first, For last, T wert, Binary comp = {}, Proj proj = {}) 

Beschreibung: Bestimmt die letzte Position, an der ein Element eingefügt werden kann, ohne die aufsteigende Ordnung der Folge [first,last) zu zerstören.

std::pair<For, For> equal_range (For first, For last, T wert) 
std::pair<For, For> equal_range (For first, For last, T wert, Comp comp) 
 
Range ranges::equal_range (Range r, T wert, Binary comp = {}, Proj proj = {}) 
Range ranges::equal_range (For first, For last, T wert, Binary comp = {}, Proj proj = {}) 

Beschreibung: Bestimmt den Teilbereich der aufsteigend geordneten Folge [first,last), der mit dem wert übereinstimmt.

Minimum und Maximum

const T& min (const T& a, const T& b) 
const T& min (const T& a, const T& b, Binary comp)
T min (std::initializer_list<T> values)  
T min (std::initializer_list<T> values, Binary comp)  
 
const T& ranges::min (const T& a, const T& b, Binary comp = {}, Proj proj = {})
T ranges::min (std::initializer_list<T> values, Binary comp = {}, Proj proj = {})
T ranges::min (Range r, Binary comp = {}, Proj proj = {})

Beschreibung: Liefert den kleinsten Wert.

const T& max (const T& a, const T& b) 
const T& max (const T& a, const T& b, Binary comp) 
T max (std::initializer_list<T> values)  
T max (std::initializer_list<T> values, Binary comp)  
 
const T& ranges::max (const T& a, const T& b, Binary comp = {}, Proj proj = {})
T ranges::max (std::initializer_list<T> values, Binary comp = {}, Proj proj = {})
T ranges::max (Range r, Binary comp = {}, Proj proj = {})

Beschreibung: Liefert den größten Wert.

std::pair<T,T> minmax (const T& a, const T& b) 
std::pair<T,T> minmax (const T& a, const T& b, Binary comp)
std::pair<T,T> minmax (std::initializer_list<T> values)  
std::pair<T,T> minmax (std::initializer_list<T> values, Binary comp)  
 
[min,max] = ranges::minmax (const T& a, const T& b, Binary comp = {}, Proj proj = {})
[min,max] = ranges::minmax (std::initializer_list<T> values, Binary comp = {}, Proj proj = {})
[min,max] = ranges::minmax (Range r, Binary comp = {}, Proj proj = {})

Beschreibung: Liefert kleinsten und größten Wert als geordnetes Paar (first <= second).

For min_element (For first, For last) 
For min_element (For first, For last, Binary comp) 
For min_element (Exec pol, For first, For last) 
For min_element (Exec pol, For first, For last, Binary comp) 
 
For ranges::min_element (Range r, Binary comp = {}, Proj proj = {})
For ranges::min_element (For first, For last, Binary comp = {}, Proj proj = {})

Beschreibung: Liefert einen Iterator auf das kleinste Element des Bereiches [first,last).

For max_element (For first, For last) 
For max_element (For first, For last, Binary comp) 
For max_element (Exec pol, For first, For last) 
For max_element (Exec pol, For first, For last, Binary comp) 
 
For ranges::max_element (Range r, Binary comp = {}, Proj proj = {})
For ranges::max_element (For first, For last, Binary comp = {}, Proj proj = {})

Beschreibung: Liefert einen Iterator auf das größte Element des Bereiches [first,last).

std::pair<For,For> minmax_element (For first, For last) 
std::pair<For,For> minmax_element (For first, For last, Binary comp) 
std::pair<For,For> minmax_element (Exec pol, For first, For last) 
std::pair<For,For> minmax_element (Exec pol, For first, For last, Binary comp) 
 
Range ranges::minmax_element (Range r, Binary comp = {}, Proj proj = {})
Range ranges::minmax_element (For first, For last, Binary comp = {}, Proj proj = {})

Beschreibung: Liefert am weitesten links stehende Minimumposition und am weitesten rechts stehende Maximumposition als Paar {m,M}.

const T& clamp (const T& value, const T& low, const T& high)              // C++17
const T& clamp (const T& value, const T& low, const T& high, Binary comp) 

Beschreibung: Begrenzt Wert auf das Intervall [low,high].

Vergleichen

bool equal (For first, For last, For2 first2) 
bool equal (For first, For last, For2 first2, Binary pred) 
bool equal (For first, For last, For2 first2, For2 last2) 
bool equal (For first, For last, For2 first2, For2 last2, Binary pred) 
bool equal (Exec pol, For first, For last, For2 first2) 
bool equal (Exec pol, For first, For last, For2 first2, Binary pred) 
bool equal (Exec pol, For first, For last, For2 first2, For2 last2) 
bool equal (Exec pol, For first, For last, For2 first2, For2 last2, Binary pred) 
 
bool ranges::equal (Range1 r1, Range2 r2, Binary pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) 
bool ranges::equal (For first, For last, For2 first2, For2 last2, Binary pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) 

Beschreibung: Ist wahr, wenn die Bereiche [first,last) und [first2,…) elementweise übereinstimmen bzw. paarweise das Prädikat pred(proj1(x),proj2(y)) erfüllen.

bool lexicographical_compare (In first, In last, In2 first2, In2 last2) 
bool lexicographical_compare (In first, In last, In2 first2, In2 last2, Binary comp) 
bool lexicographical_compare (Exec pol, In first, In last, In2 first2, In2 last2) 
bool lexicographical_compare (Exec pol, In first, In last, In2 first2, In2 last2, Binary comp) 
 
bool ranges::lexicographical_compare (Range1 r1, Range2 r2, Binary comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) 
bool ranges::lexicographical_compare (In first, In last, In2 first2, In2 last2, Binary comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) 

Beschreibung: Ist wahr, wenn der Bereich [first,last) lexikographisch vor [first2,last2) einzuordnen ist.

std::pair<In, In2> mismatch (In first, In last, In2 first2) 
std::pair<In, In2> mismatch (In first, In last, In2 first2, Binary pred) 
std::pair<In, In2> mismatch (In first, In last, In2 first2, In2 last2) 
std::pair<In, In2> mismatch (In first, In last, In2 first2, In2 last2, Binary pred) 
std::pair<In, In2> mismatch (Exec pol, In first, In last, In2 first2) 
std::pair<In, In2> mismatch (Exec pol, In first, In last, In2 first2, Binary pred) 
std::pair<In, In2> mismatch (Exec pol, In first, In last, In2 first2, In2 last2) 
std::pair<In, In2> mismatch (Exec pol, In first, In last, In2 first2, In2 last2, Binary pred)
 
[pos1, pos2] = ranges::mismatch (Range1 r1, Range2 r2, Binary pred = {}, Proj1 proj = {}, Proj2 proj2 = {})
[pos1, pos2] = ranges::mismatch (In first, In last, In2 first2, In2 last2, Binary pred = {}, Proj1 proj = {}, Proj2 proj2 = {})

Beschreibung: Liefert ein Paar von Iteratoren {pos1, pos2}, ab denen die Bereiche [first,last) und [first2,…) nicht mehr übereinstimmen bzw. das Prädikat pred(proj1(pos1),proj2(pos2)) nicht mehr erfüllen.

Modifizierende Algorithmen

Tauschen

void iter_swap (Iter a, Iter b) 

Beschreibung: Vertauscht die Werte der Objekte, auf die die Iteratoren von a und b verweisen.

For2 swap_ranges (For first, For last, For2 first) 
For2 swap_ranges (Exec pol, For first, For last, For2 first) 
 
[pos, pos2] = ranges::swap_ranges (Range1 r1, Range2 r2) 
[pos, pos2] = ranges::swap_ranges (For first, For last, For2 first, For2 Last2) 

Beschreibung: Tauscht die Werte in den Bereichen [first,last) und [first2,…) aus.

Kopieren

Out copy (In first, In last, Out result) 
Out copy (Exec pol, In first, In last, Out result) 
 
[last, res] = ranges::copy (Range r, Out result) 
[last, res] = ranges::copy (In first, In last, Out result) 

Beschreibung: Kopiert die Werte des Bereiches [first,last) nach [result,…).

Out copy_if (In first, In last, Out result, Pred pred) 
Out copy_if (Exec pol, In first, In last, Out result, Pred pred) 
 
[last, res] = ranges::copy_if (Range r, Out result, Pred pred, Proj = proj = {}) 
[last, res] = ranges::copy_if (In first, In last, Out result, Pred pred, Proj = proj = {}) 

Beschreibung: Kopiert die Werte e des Bereiches [first,last) nach [result,…), die das Prädikat pred(proj(e)) erfüllen.

Out copy_n (In first, Size n, Out result) 
Out copy_n (Exec pol, In first, Size n, Out result) 
 
[last, res] = ranges::copy_n (In first, Size n, Out result) 

Beschreibung: Kopiert n Werte des Bereiches [first,first+n) nach [result,…).

Bi2 copy_backward (Bi first, Bi last, Bi2 result) 
 
[last, res] = ranges::copy_backward (Range r, Bi2 result) 
[last, res] = ranges::copy_backward (Bi first, Bi last, Bi2 result) 

Beschreibung: Kopiert die Werte des Bereiches [first,last) am Ende beginnend nach [result - (last-first),result).

Verschieben

Out move (In first, In last, Out result) 
Out move (Exec pol, In first, In last, Out result) 
 
[last, res] = ranges::move (Range r, Out result) 
[last, res] = ranges::move (In first, In last, Out result) 

Beschreibung: Verschiebt die Elemente des Bereiches [first,last) nach [result,…).

[last, res] = ranges::move_backward (Range r, Bi2 result) 
[last, res] = ranges::move_backward (Bi first, Bi last, Bi2 result) 

Beschreibung: Verschiebt die Elemente des Bereiches [first,last) am Ende beginnend nach [result - (last-first),result).

Füllen

void fill (Out first, Out last, T wert) 
void fill (Exec pol, Out first, Out last, T wert) 
 
Out ranges::fill (Range r, T wert) 
Out ranges::fill (Out first, Out last, T wert) 

Beschreibung: Füllt den Bereich [first,last) mit dem wert.

void fill_n (Out first, Size n, T wert) 
void fill_n (Exec pol, Out first, Size n, T wert) 
 
Out ranges::fill_n (Out first, Size n, T wert) 

Beschreibung: Füllt in den bei first beginnenden Bereich n mal den wert.

void generate (Out first, Out last, Func generator_obj) 
void generate (Exec pol, Out first, Out last, Func generator_obj) 
 
Out ranges::generate (Range r, Func generator_obj) 
Out ranges::generate (Out first, Out last, Func generator_obj) 

Beschreibung: Füllt den Bereich [first,last) mit der durch generator_obj erzeugten Folge von Werten.

void generate_n (Out first, Size n, Func generator_obj) 
void generate_n (Exec pol, Out first, Size n, Func generator_obj) 
 
Out ranges::generate_n (Out first, Size n, Func generator_obj) 

Beschreibung: Füllt in den bei first beginnenden Bereich n durch generator_obj erzeugte Werte.

Ersetzen

void replace (For first, For last, T alterwert, T neuerwert) 
void replace (Exec pol, For first, For last, T alterwert, T neuerwert) 
 
In ranges::replace (Range r, T alterwert, T neuerwert, Proj proj = {}) 
In ranges::replace (In first, In last, T alterwert, T neuerwert, Proj proj = {}) 

Beschreibung: Ersetzt im Bereich [first,last) alle Elemente e mit proj(e) == alterwert durch neuerwert.

void replace_if (For first, For last, Pred pred, T neuerwert) 
void replace_if (Exec pol, For first, For last, Pred pred, T neuerwert) 
 
In ranges::replace_if (Range r, Pred pred, T neuerwert, Proj proj = {}) 
In ranges::replace_if (For first, For last, Pred pred, T neuerwert, Proj proj = {}) 

Beschreibung: Ersetzt im Bereich [first,last) all jene Elemente e, auf die pred(proj(e)) zutrifft, durch neuerwert.

Out replace_copy (In first, In last, Out result, T alterwert, T neuerwert) 
Out replace_copy (Exec pol, In first, In last, Out result, T alterwert, T neuerwert) 
 
[last, out] = ranges::replace_copy (Range r, Out result, T alterwert, T neuerwert, Proj proj = {}) 
[last, out] = ranges::replace_copy (In first, In last, Out result, T alterwert, T neuerwert, Proj proj = {}) 

Beschreibung: Kopiert den Bereich [first,last) nach [result,…) und ersetzt dabei Elemente mit proj(e) == alterwert durch neuerwert.

Out replace_copy_if (In first, In last, Out result, Pre pred, T neuerwert) 
Out replace_copy_if (Exec pol, In first, In last, Out result, Pre pred, T neuerwert) 
 
[last, out] = ranges::replace_copy_if (Range r, Out result, Pre pred, T neuerwert, Proj proj = {}) 
[last, out] = ranges::replace_copy_if (In first, In last, Out result, Pre pred, T neuerwert, Proj proj = {}) 

Beschreibung: Kopiert den Bereich [first,last) nach [result,…) und ersetzt dabei all jene Elemente e, auf die pred(proj(e)) zutrifft, durch neuerwert.

Entfernen

For remove (For first, For last, T wert) 
For remove (Exec pol, For first, For last, T wert) 
 
Range ranges::remove (Range r, T wert, Proj proj = {}) 
Range ranges::remove (For first, For last, T wert, Proj proj = {}) 

Beschreibung: Entfernt im Bereich [first,last) alle Elemente e mit proj(e) == wert.

For remove_if (For first, For last, Pred pred) 
For remove_if (Exec pol, For first, For last, Pred pred) 
 
Range ranges::remove_if (Range r, Pred pred, Proj proj = {}) 
Range ranges::remove_if (For first, For last, Pred pred, Proj proj = {}) 

Beschreibung: Entfernt im Bereich [first,last) alle Elemente e, auf die pred(proj(e)) zutrifft.

Out remove_copy (In first, In last, Out result, T wert) 
Out remove_copy (Exec pol, In first, In last, Out result, T wert) 
 
[last, res] = ranges::remove_copy (Range r, Out result, T wert, Proj proj = {}) 
[last, res] = ranges::remove_copy (In first, In last, Out result, T wert, Proj proj = {}) 

Beschreibung: Kopiert den Bereich [first,last) nach [result,…) und entfernt dabei alle Elemente e mit dem angegebenen wert bzw. auf die pred(proj(e)) zutrifft.

Out remove_copy_if (In first, In last, Out result, Pred pred) 
Out remove_copy_if (Exec pol, In first, In last, Out result, Pred pred) 
 
[last, res] = ranges::remove_copy_if (Range r, Out result, Pred pred, Proj proj = {}) 
[last, res] = ranges::remove_copy_if (In first, In last, Out result, Pred pred, Proj proj = {}) 

Beschreibung: Kopiert den Bereich [first,last) nach [result,…) und entfernt dabei alle Elemente e mit dem angegebenen wert bzw. auf die pred(proj(e)) zutrifft.

For unique (For first, For last) 
For unique (For first, For last, Binary pred) 
For unique (Exec pol, first, For last) 
For unique (Exec pol, For first, For last, Binary pred) 
 
Range ranges::unique (Range r, Binary pred = {}, Proj proj = {}) 
Range ranges::unique (For first, For last, Binary pred = {}, Proj proj = {}) 

Beschreibung: Entfernt alle Elemente e aus dem Bereich [first,last), die mit ihren Vorgänger übereinstimmen bzw. auf die pred(proj(vorgaenger),proj(e)) zutrifft.

Out unique_copy (In first, In last, Out result) 
Out unique_copy (In first, In last, Out result, Binary pred) 
Out unique_copy (Exec pol, In first, In last, Out result) 
Out unique_copy (Exec pol, In first, In last, Out result, Binary pred) 
 
[last,res] = ranges::unique_copy (Raneg r, Out result, Binary pred = {}, Proj proj = {}) 
[last,res] = ranges::unique_copy (In first, In last, Out result, Binary pred = {}, Proj proj = {}) 

Beschreibung: Kopiert den Bereich [first,last) nach [result,…) und übergeht dabei alle Elemente e aus dem Bereich [first,last), die mit ihren Vorgänger übereinstimmen bzw. auf die pred(proj(vorgaenger), proj(e)) zutrifft.

Umwandeln

Out transform (In first, In last, Out result, Func func) 
Out transform (In first, In last, In first2, Out result, Binary func) 
Out transform (Exec pol, In first, In last, Out result, Func func) 
Out transform (Exec pol, In first, In last, In first2, Out result, Binary func) 
 
[end,res] = ranges::transform (Range r, Out result, Func func, Proj proj = {}) 
[end,res] = ranges::transform (In first, In last, Out result, Func func, Proj proj = {}) 
 
[end1,end2,res] = ranges::transform (Range1 r1, Range2 r2, Out result, Binary func, Proj1 proj1 = {}, Proj2 proj2 = {}) 
[end1,end2,res] = ranges::transform (In first, In last, In2 first2, In2 last2, Out result, Binary func, Proj1 proj1 = {}, Proj2 proj2 = {}) 

Beschreibung: Errechnet aus den Elementen x des Bereiches [first,last) und Elementen y des Bereiches [first2, last2) eine Folge von Werten func(proj(x)) bzw. func(proj1(x), proj2(y)) und legt diese im Bereich [result,…) ab.

Mutierende Algorithmen

Umkehren

void reverse (Bi first, Bi last) 
void reverse (Exec pol, Bi first, Bi last) 
 
Bi ranges::reverse (Range r) 
Bi ranges::reverse (Bi first, Bi last) 

Beschreibung: Kehrt die Reihenfolge des Elemente im Bereich [first,last) um.

Out reverse_copy (Bi first, Bi last, Out result) 
Out reverse_copy (Exec pol, Bi first, Bi last, Out result)
 
[last,res] = ranges::reverse_copy (Range r, Out result) 
[last,res] = ranges::reverse_copy (Bi first, Bi last, Out result) 

Beschreibung: Kopiert den Bereich [first,last) in umgekehrter Reihenfolge nach [result,…).

Rotieren

For rotate (For first, For middle, For last) 
For rotate (Exec pol, For first, For middle, For last) 
 
Range ranges::rotate (For first, For middle, For last) 

Beschreibung: Vertauscht die Bereiche [first,middle) und [middle,last).

Out rotate_copy (For first, For middle, For last, Out result) 
Out rotate_copy (Exec pol, For first, For middle, For last, Out result) 
 
[last,res] = ranges::rotate_copy (Range r, For last, Out result) 
[last,res] = ranges::rotate_copy (For first, For middle, For last, Out result) 

Beschreibung: Kopiert die Bereiche [middle,last) und [first,middle) in dieser Reihenfolge nach [result,…).

Durcheinanderbringen

void shuffle (Ran first, Ran last, UniformRandomBitGenerator zufall)  // C++11
 
Ran ranges::shuffle (Range r, UniformRandomBitGenerator zufall)
Ran ranges::shuffle (Ran first, Ran last, UniformRandomBitGenerator zufall)

Beschreibung: Ordnet den Bereich [first,last) zufällig um.

Out sample (In first, In last, Out first2, N n, UniformRandomBitGenerator zufall)  // C++17
 
Out ranges::sample (Range r, Out first2, N n, UniformRandomBitGenerator zufall)
Out ranges::sample (In first, In last, Out first2, N n, UniformRandomBitGenerator zufall)

Beschreibung: Liefert n Werte aus dem Bereich [first,last) in zufälliger Folge.

void random_shuffle (Ran first, Ran last)              // bis C++14, entfernt in C++17 
void random_shuffle (Ran first, Ran last, Func zufall) 

Beschreibung: Ordnet den Bereich [first,last) zufällig um. Der Aufruf zufall(n) sollte Zahlen im Bereich [0,n) liefern.

Systematisches Umordnen

bool is_permutation (For first, For last, For2 first2) 
bool is_permutation (For first, For last, For2 first2, Binary comp) 
bool is_permutation (For first, For last, For2 first2, For2 last2) 
bool is_permutation (For first, For last, For2 first2, For2 last2, Binary comp) 
 
bool ranges::is_permutation (Range1 r1, Range2 r2, Binary comp = {}, Proj1 proj1 = {}, Proj2 proj2 ={}) 
bool ranges::is_permutation (For first, For last, For2 first2, For2 last2, Binary comp = {}, Proj1 proj1 = {}, Proj2 proj2 ={}) 

Beschreibung: Prüft, ob [first2,…) eine Permutation des Bereiches [first,last) darstellt.

bool next_permutation (Bi first, Bi last) 
bool next_permutation (Bi first, Bi last, Binary comp) 
 
[last,B] = ranges::next_permutation (Range r, Binary comp = {}, Proj proj = {}) 
[last,B] = ranges::next_permutation (Bi first, Bi last, Binary comp = {}, Proj proj = {}) 

Beschreibung: Erzeugt die nächste Permutation des Bereiches [first,last).

bool prev_permutation (Bi first, Bi last) 
bool prev_permutation (Bi first, Bi last, binary comp) 
 
[last,B] = ranges::prev_permutation (Range r, Binary comp = {}, Proj proj = {}) 
[last,B] = ranges::prev_permutation (Bi first, Bi last, Binary comp = {}, Proj proj = {}) 

Beschreibung: Erzeugt die vorhergehende Permutation des Bereiches [first,last).

Links/rechts schieben

For shift_left (For first, For last, difference_type n);            // C++20
For shift_left (Exec pol, For first, For last, difference_type n);

Beschreibung: Verschiebt die Elemente des Bereichs [first, last) um n Positionen nach links.

For shift_right (For first, For last, difference_type n);           // C++20
For shift_right (Exec pol, For first, For last, difference_type n);

Beschreibung: Verschiebt die Elemente des Bereichs [first, last) um n Positionen nach rechts.

Sortieren

Vollständiges Sortieren

bool is_sorted (For first, For last) 
bool is_sorted (For first, For last, Binary comp) 
bool is_sorted (Exec pol, For first, For last) 
bool is_sorted (Exec pol, For first, For last, Binary comp) 
 
bool ranges::is_sorted (Range r, Binary comp = {}, Proj proj = {}) 
bool ranges::is_sorted (For first, For last, Binary comp = {}, Proj proj = {}) 

Beschreibung: Prüft, ob der Bereich [first,last) in aufsteigender Folge sortiert ist.

void sort (Ran first, Ran last) 
void sort (Ran first, Ran last, Comp comp) 
void sort (Exec pol, Ran first, Ran last) 
void sort (Exec pol, Ran first, Ran last, Comp comp) 
 
Ran ranges::sort (Range r, Comp comp = {}, Proj proj = {}) 
Ran ranges::sort (Ran first, Ran last, Comp comp = {}, Proj proj = {}) 

Beschreibung: Sortiert den Bereich [first,last) in aufsteigender Folge.

void stable_sort (Ran first, Ran last) 
void stable_sort (Ran first, Ran last, Comp comp) 
void stable_sort (Exec pol, Ran first, Ran last) 
void stable_sort (Exec pol, Ran first, Ran last, Comp comp) 
 
Ran ranges::stable_sort (Range r, Comp comp = {}, Proj proj = {}) 
Ran ranges::stable_sort (Ran first, Ran last, Comp comp = {}, Proj proj = {}) 

Beschreibung: Sortiert den Bereich [first,last) in aufsteigender Folge. Die relative Anordnung wertgleicher Elemente bleibt erhalten.

Teilweises Sortieren

For is_sorted_until (For first, For last) 
For is_sorted_until (For first, For last, Binary comp) 
For is_sorted_until (Exec pol, For first, For last) 
For is_sorted_until (Exec pol, For first, For last, Binary comp) 
 
For ranges::is_sorted_until (Range r, Binary comp = {}, Proj proj = {}) 
For ranges::is_sorted_until (For first, For last, Binary comp = {}, Proj proj = {}) 

Beschreibung: Liefert den Iterator i auf das Ende des aufsteigend sortierten Teilbereichs [first,i) von [first,last).

void partial_sort (Ran first, Ran middle, Ran last) 
void partial_sort (Ran first, Ran middle, Ran last, Binary comp) 
void partial_sort (Exec pol, Ran first, Ran middle, Ran last) 
void partial_sort (Exec pol, Ran first, Ran middle, Ran last, Binary comp) 
 
Ran ranges::partial_sort (Range r, Ran middle, Binary comp = {}, Proj proj = {}) 
Ran ranges::partial_sort (Ran first, Ran middle, Ran last, Binary comp = {}, Proj proj = {}) 

Beschreibung: Bringt die kleinsten Elemente des Bereiches [first,last) aufsteigend geordnet im Bereich [first,middle) unter.

Ran partial_sort_copy (In first, In last, Ran result_first, Ran result_last) 
Ran partial_sort_copy (In first, In last, Ran result_first, Ran result_last, Binary comp) 
Ran partial_sort_copy (Exec pol, In first, In last, Ran result_first, Ran result_last) 
Ran partial_sort_copy (Exec pol, In first, In last, Ran result_first, Ran result_last, Binary comp) 
 
[last,res] = partial_sort_copy (Range1 r1, Range2 result, Binary comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) 
[last,res] = partial_sort_copy (In first, In last, Ran result_first, Ran result_last, Binary comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) 

Beschreibung: Kopiert die kleinsten Elemente des Bereiches [first,last) aufsteigend geordnet in den Bereich [result_first,result_last).

void nth_element (Ran first, Ran nth, Ran last) 
void nth_element (Ran first, Ran nth, Ran last, Binary comp) 
void nth_element (Exec pol, Ran first, Ran nth, Ran last) 
void nth_element (Exec pol, Ran first, Ran nth, Ran last, Binary comp) 
 
Ran ranges::nth_element (Range r, Ran nth, Binary comp = {}, Projproj = {}) 
Ran ranges::nth_element (Ran first, Ran nth, Ran last, Binary comp = {}, Projproj = {}) 

Beschreibung: Sortiert den Bereich [first,last) soweit, dass das nte Element an der richtigen Position steht und sich links davon nur kleinere, rechts davon nur größere Elementwerte befinden.

Aufteilen

bool is_partitioned (In first, In last, Pred pred) 
bool is_partitioned (Exec pol, In first, In last, Pred pred) 
 
bool ranges::is_partitioned (Range r, Pred pred, Proj proj = {}) 
bool ranges::is_partitioned (In first, In last, Pred pred, Proj proj = {}) 

Beschreibung: Prüft, ob im Bereich [first,last) alle Elemente e, auf die pred(proj(e)) zutrifft, links von denen stehen, auf die es nicht zutrifft.

For partition (For first, For last, Pred pred) 
For partition (Exec pol, For first, For last, Pred pred) 
 
Range range::partition (Range r, Pred pred, Proj proj = {}) 
Range range::partition (For first, For last, Pred pred, Proj proj = {}) 

Beschreibung: Bringt alle Elemente e des Bereiches [first,last), auf die pred(proj(e)) zutrifft, nach links, alle anderen nach rechts.

For stable_partition (For first, For last, Pred pred) 
For stable_partition (Exec pol, For first, For last, Pred pred) 
 
Range range::stable_partition (Range r, Pred pred, Proj proj = {}) 
Range range::stable_partition (For first, For last, Pred pred, Proj proj = {}) 

Beschreibung: Bringt alle Elemente e des Bereiches [first,last), auf die pred(proj(e)) zutrifft, nach links, alle anderen nach rechts. Die relative Ordnung der Elemente in beiden Gruppen bleibt erhalten.

std:pair<Out, Out2> partition_copy (In first, In last, Out good, Out2 bad, Pred pred) 
std:pair<Out, Out2> partition_copy (Exec pol, In first, In last, Out good, Out2 bad, Pred pred) 
 
[last, endgood, endbad] = ranges::partition_copy (Range r, Out good, Out2 bad, Pred pred, Proj proj = {}) 
[last, endgood, endbad] = ranges::partition_copy (In first, In last, Out good, Out2 bad, Pred pred, Proj proj = {}) 

Beschreibung: Kopiert alle Elemente e des Bereiches [first,last), auf die pred(proj(e)) zutrifft, in den durch good angegebenen Bereich, alle anderen nach bad.

For partition_point (For first, For last, Pred pred) 
 
For ranges::partition_point (Range r, Pred pred, Proj proj = {}) 
For ranges::partition_point (For first, For last, Pred pred, Proj proj = {}) 

Beschreibung: Liefert den Iterator hinter das letzte Element e im partitionierten Bereich [first,last), auf welches pred(proj(e)) zutrifft.

Mischen

Out merge (In first, In last, In2 first2, In2 last2, Out result) 
Out merge (In first, In last, In2 first2, In2 last2, Out result, Binary comp) 
Out merge (Exec pol, In first, In last, In2 first2, In2 last2, Out result) 
Out merge (Exec pol, In first, In last, In2 first2, In2 last2, Out result, binary comp) 
 
[last1,last2,res] = ranges::merge (Range1 r1, Range2 r2, Out result, Binary comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) 
[last1,last2,res] = ranges::merge (In first, In last, In2 first2, In2 last2, Out result, 
                                   Binary comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) 

Beschreibung: Führt zwei aufsteigend sortierte Bereiche [first,last) und [first2,last2) in [result,…) aufsteigend sortiert zusammen.

void inplace_merge (Bi first, Bi middle, Bi last) 
void inplace_merge (Bi first, Bi middle, Bi last, Binary comp) 
void inplace_merge (Exec pol, Bi first, Bi middle, Bi last) 
void inplace_merge (Exec pol, Bi first, Bi middle, Bi last, Binary comp) 
 
Bi ranges::inplace_merge (Range r, Bi middle, Binary comp = {}, Proj proj = {}) 
Bi ranges::inplace_merge (Bi first, Bi middle, Bi last, Binary comp = {}, Proj proj = {}) 

Beschreibung: Ordnet die in sich aufsteigend sortierten Bereiche [first,middle) und [middle,last2) so um, dass der gesamte Bereich aufsteigend sortiert ist.

Mengenoperationen

bool includes (In first1, In last1, In2 first2, In2 last2) 
bool includes (In first1, In last1, In2 first2, In2 last2, Binary comp) 
bool includes (Exec pol, In first1, In last1, In2 first2, In2 last2) 
bool includes (Exec pol, In first1, In last1, In2 first2, In2 last2, Binary comp) 
 
bool ranges::includes (Range1 r1, Range2 r2, Binary comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) 
bool ranges::includes (In first1, In last1, In2 first2, In2 last2, Binary comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) 

Beschreibung: Ist true, wenn jedes Element des aufsteigend sortierten Bereiches [first2,last2) im aufsteigend sortierten Bereich [first,last) enthalten ist.

Out set_union (In first1, In last1, In2 first2, In2 last2, Out result) 
Out set_union (In first1, In last1, In2 first2, In2 last2, Out result, Binary comp) 
Out set_union (Exec pol, In first1, In last1, In2 first2, In2 last2, Out result) 
Out set_union (Exec pol, In first1, In last1, In2 first2, In2 last2, Out result, Binary comp) 
 
[last1,last2,res] = ranges::set_union (Range1 r1, Range2 r2, Out result, 
                                       Binary comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) 
[last1,last2,res] = ranges::set_union (In first1, In last1, In2 first2, In2 last2, Out result, 
                                       Binary comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) 

Beschreibung: Schreibt die Vereinigung der beiden sortierten Mengen [first,last) und [first2,last2) sortiert in den Bereich [result,…).

Out set_intersection (In first1, In last1, In2 first2, In2 last2, Out result) 
Out set_intersection (In first1, In last1, In2 first2, In2 last2, Out result, Binary comp) 
Out set_intersection (Exec pol, In first1, In last1, In2 first2, In2 last2, Out result) 
Out set_intersection (Exec pol, In first1, In last1, In2 first2, In2 last2, Out result, Binary comp) 
 
[last1,last2,res] = ranges::set_intersection (Range1 r1, Range2 r2, Out result, 
                                              Binary comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) 
[last1,last2,res] = ranges::set_intersection (In first1, In last1, In2 first2, In2 last2, Out result, 
                                              Binary comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) 

Beschreibung: Schreibt den Durchschnitt der beiden sortierten Mengen [first,last) und [first2,last2) sortiert in den Bereich [result,…).

Out set_difference (In first1, In last1, In2 first2, In2 last2, Out result) 
Out set_difference (In first1, In last1, In2 first2, In2 last2, Out result, Binary comp) 
Out set_difference (Exec pol, In first1, In last1, In2 first2, In2 last2, Out result) 
Out set_difference (Exec pol, In first1, In last1, In2 first2, In2 last2, Out result, Binary comp) 
 
[last1,res] = ranges::set_difference (Range1 r1, Range2 r2, Out result, 
                                      Binary comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) 
[last1,res] = ranges::set_difference (In first1, In last1, In2 first2, In2 last2, Out result, 
                                      Binary comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) 

Beschreibung: Kopiert jene Elemente des sortierten Bereichs [first,last), die nicht in [first2,last2) vorkommen, sortiert in den Bereich [result,…).

Out set_symmetric_difference (In first1, In last1, In2 first2, In2 last2, Out result) 
Out set_symmetric_difference (In first1, In last1, In2 first2, In2 last2, Out result, Binary comp) 
Out set_symmetric_difference (Exec pol, In first1, In last1, In2 first2, In2 last2, Out result) 
Out set_symmetric_difference (Exec pol, In first1, In last1, In2 first2, In2 last2, Out result, Binary comp) 
 
[last1,res] = ranges::set_symmetric_difference (Range1 r1, Range2 r2, Out result, 
                                                Binary comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) 
[last1,res] = ranges::set_symmetric_difference (In first1, In last1, In2 first2, In2 last2, Out result, 
                                                Binary comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) 

Beschreibung: Kopiert jene Elemente, die nur in einem der beiden sortierten Bereiche [first,last) und [first2,last2) vorkommen, sortiert in den Bereich [result,…).

Heapoperationen

bool is_heap (Ran first, Ran last) 
bool is_heap (Ran first, Ran last, Binary comp) 
 
bool is_heap (Exec pol, Ran first, Ran last) 
bool is_heap (Exec pol, Ran first, Ran last, Binary comp) 
 
bool ranges::is_heap (Range r, Binary comp = {}, Proj proj = {}) 
bool ranges::is_heap (Ran first, Ran last, Binary comp = {}, Proj proj = {}) 

Beschreibung: Prüft, ob der Bereich [first,last) als Heap geordnet ist.

Ran is_heap_until (Ran first, Ran last) 
Ran is_heap_until (Ran first, Ran last, Binary comp) 
Ran is_heap_until (Exec pol, Ran first, Ran last) 
Ran is_heap_until (Exec pol, Ran first, Ran last, Binary comp) 
 
Ran ranges::is_heap_until (Range r, Binary comp = {}, Proj proj = {}) 
Ran ranges::is_heap_until (Ran first, Ran last, Binary comp = {}, Proj proj = {}) 

Beschreibung: Liefert den Iterator auf das Ende des als Heap geordneten Teilbereiches von [first,last).

void push_heap (Ran first, Ran last) 
void push_heap (Ran first, Ran last, Binary comp) 
 
Ran ranges::push_heap (Range r, Binary comp = {}, proj = {}) 
Ran ranges::push_heap (Ran first, Ran last, Binary comp = {}, proj = {}) 

Beschreibung: Fügt das letzte Element des Bereiches [first,last) in den davor liegenden, als Heap geordneten Bereich ein.

void pop_heap (Ran first, Ran last) 
void pop_heap (Ran first, Ran last, Binary comp) 
 
Ran ranges::pop_heap (Range r, Binary comp = {}, proj = {}) 
Ran ranges::pop_heap (Ran first, Ran last, Binary comp = {}, proj = {}) 

Beschreibung: Vertauscht *first und *(last-1) des als Heap geordneten Bereiches [first,last) und ordnet den vor dem letzten Element liegenden Teilbereich wieder zu einem Heap um.

void make_heap (Ran first, Ran last) 
void make_heap (Ran first, Ran last, Binary comp) 
 
Ran ranges::make_heap (Range r, Binary comp = {}, proj = {}) 
Ran ranges::make_heap (Ran first, Ran last, Binary comp = {}, proj = {}) 

Beschreibung: Ordnet den Bereich [first,last) zu einem Heap um.

void sort_heap (Ran first, Ran last) 
void sort_heap (Ran first, Ran last, Binary comp) 
 
Ran ranges::sort_heap (Range r, Binary comp = {}, proj = {}) 
Ran ranges::sort_heap (Ran first, Ran last, Binary comp = {}, proj = {}) 

Beschreibung: Sortiert den als Heap vorgegebenen Bereich [first,last) aufsteigend.

Siehe auch

1)
genauer: std::invoke(proj,e)
kennen/include/algorithm.txt · Zuletzt geändert: 2023-10-14 12:24 von rrichter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki