kennen:lib:partial_sort_copy
Inhaltsverzeichnis
partial_sort_copy()
#include
<algorithm>
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 = {})
Kopiert die kleinsten Elemente des Bereiches [first,last) aufsteigend geordnet in den Bereich [result_first,result_last).
Parameter
first | Anfang des Bereiches |
last | Ende des Bereiches |
result_first | Anfang des Zielbereiches |
result_last | Ende des Zielbereiches |
comp | Vergleichskriterium (Vorgabe = less ) |
proj1 , proj2 | einstellige Funktoren (Vorgabe = std::identity ) |
pol | parallele Ausführungsart |
Ergebnis
Rückgabewert: result_first+N
bzw. {last,result_first+N}
als Struktur mit Elementen namens in, out
mit N = min(last-first, result_last-result_first)
.
Siehe auch
Beispiel
- partial_sort_copy.cpp
#include <algorithm> #include <iostream> #include <string> #include <vector> struct Person { std::string name; int born; int died; }; struct Person2 { std::string name; int age; Person2(Person p = {}) : name(p.name) , age(p.died-p.born) { } }; int main() { auto persons = std::vector<Person> { { "Galilei", 1564, 1642 }, { "Newton" , 1642, 1726 }, { "Hawking", 1942, 2018 }, }; for (auto [name, born, died] : persons) { std::cout << name << '\t' << born << '-' << died << '\n'; } std::cout << "-----------------\n"; auto persons2 = std::vector<Person2>(2); std::ranges::partial_sort_copy(persons, persons2, {}, &Person::name, &Person2::name); for (auto [name, age] : persons2) { std::cout << name << '\t' << age << '\n'; } } /* Galilei 1564-1642 Newton 1642-1726 Hawking 1942-2018 ----------------- Galilei 78 Hawking 76 */
kennen/lib/partial_sort_copy.txt · Zuletzt geändert: 2023-10-14 12:17 von rrichter