std::multimap<Key,T,Compare,Allocator>:: key_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::multimap
| Member functions | |||||||||||||||||||||||||||
| Non-member functions | |||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||
| Deduction guides (C++17) | |||||||||||||||||||||||||||
|
key_compare key_comp
(
)
const
;
|
(constexpr seit C++26) | |
Gibt das Funktionsobjekt zurück, das die Schlüssel vergleicht, welches eine Kopie des Schlüsselvergleichsobjekts ist, das von * this verwendet wird.
Inhaltsverzeichnis |
Rückgabewert
Das Schlüsselvergleichsfunktionsobjekt.
Komplexität
Konstante.
Beispiel
Diesen Code ausführen
#include <iostream> #include <map> #include <utility> // Beispiel-Modul-97-Schlüsselvergleichsfunktion struct ModCmp { bool operator()(int lhs, int rhs) const { return (lhs % 97) < (rhs % 97); } }; int main() { std::multimap<int, char, ModCmp> cont; cont = {{1, 'a'}, {2, 'b'}, {3, 'c'}, {4, 'd'}, {5, 'e'}}; auto comp_func = cont.key_comp(); for (const auto it : cont) { const bool before = comp_func(it.first, 100); const bool after = comp_func(100, it.first); std::cout << "Schlüssel (" << it.first << ',' << it.second << ") "; if (!before && !after) std::cout << "äquivalent zu Schlüssel (100)\n"; else if (before) std::cout << "geht vor Schlüssel (100)\n"; else if (after) std::cout << "geht nach Schlüssel (100)\n"; else std::unreachable(); } }
Ausgabe:
(1,a) geht vor Schlüssel (100) (2,b) geht vor Schlüssel (100) (3,c) äquivalent zu Schlüssel (100) (4,d) geht nach Schlüssel (100) (5,e) geht nach Schlüssel (100)
Siehe auch
gibt die Funktion zurück, die Schlüssel in Objekten vom Typ
value_type
vergleicht
(öffentliche Elementfunktion) |