multimap and multiset
Allow duplicate keys.
Allowing Duplicates
std::multimap and std::multiset are like map and set but they allow duplicate keys. Everything stays sorted.
#include <iostream>
#include <set>
int main() {
std::multiset<int> ms{1, 2, 2, 3, 3, 3};
for (int x : ms) std::cout << x << ' ';
std::cout << '\n';
return 0;
}multiset Insertion
Every insert() into a multiset succeeds, even for repeated values, growing the container each time.
#include <iostream>
#include <set>
int main() {
std::multiset<std::string> ms;
ms.insert("a");
ms.insert("a");
ms.insert("a");
std::cout << ms.size() << " elements\n";
return 0;
}All lessons in this course
- std::map
- std::set
- multimap and multiset
- Custom Comparators