std::flat_set<Key,Compare,KeyContainer>:: value_comp
From cppreference.net
C++
Containers library
|
(C++17)
|
||||
| Sequence | ||||
|
(C++11)
|
||||
|
(C++26)
|
||||
|
(C++26)
|
||||
|
(C++11)
|
||||
| Associative | ||||
| Unordered associative | ||||
|
(C++11)
|
||||
|
(C++11)
|
||||
|
(C++11)
|
||||
|
(C++11)
|
||||
| Adaptors | ||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
| Views | ||||
|
(C++20)
|
||||
|
(C++23)
|
||||
| Tables | ||||
| Iterator invalidation | ||||
| Member function table | ||||
| Non-member function table |
std::flat_set
|
value_compare value_comp
(
)
const
;
|
(seit C++23)
(constexpr seit C++26) |
|
Gibt das Funktionsobjekt zurück, das die Werte vergleicht. Es ist dasselbe wie key_comp() .
Inhaltsverzeichnis |
Rückgabewert
Das Wertvergleichsfunktionsobjekt.
Komplexität
Konstante.
Beispiel
Diesen Code ausführen
#include <iostream> #include <flat_set> #include <utility> // Beispiel-Modul-97-Schlüsselvergleichsfunktion struct ModCmp { bool operator()(int lhs, int rhs) const { return (lhs % 97) < (rhs % 97); } }; int main() { std::flat_set<int, ModCmp> cont{1, 2, 3, 4, 5}; // Gleiches Verhalten wie key_comp() auto comp_func = cont.value_comp(); for (const int val{100}; const int key : cont) { const bool before = comp_func(key, val); const bool after = comp_func(val, key); std::cout << "Schlüssel (" << key << ") "; if (!before && !after) std::cout << "äquivalent zu Schlüssel (" << val << ")\n"; else if (before) std::cout << "kommt vor Schlüssel (" << val << ")\n"; else if (after) std::cout << "kommt nach Schlüssel (" << val << ")\n"; else std::unreachable(); } }
Ausgabe:
Schlüssel (1) kommt vor Schlüssel (100) Schlüssel (2) kommt vor Schlüssel (100) Schlüssel (3) äquivalent zu Schlüssel (100) Schlüssel (4) kommt nach Schlüssel (100) Schlüssel (5) kommt nach Schlüssel (100)
Siehe auch
|
gibt die Funktion zurück, die Schlüssel vergleicht
(öffentliche Elementfunktion) |