I don't understand why multimap exists if we can create map of vectors or map of sets. For me only differences are:
- using
equal_range
in multimap for getting elements of a key and in map of vectors we simply use[]
operator and have vector of elements. - using
multimap.insert(make_pair(key,value))
in multimap for adding elements andmap_of_vectors[key].push_back(value)
in map of vectors.
So why use multimap? For me it's better to have a vector than two iterators to get all values of a key.
This question applies also to unordered_map of vectors and unordered_multimap.
multimap
:/ – Matthieu M.push_back
you won't keep it) – Jcao02map<K, V>
vs.set<pair<K, V>, cmp_first<K, V>>
where cmp_first compares the.first
member. – lorro