I understand the usage on sets in C++, but why do multisets exist? What are some real world applications where multisets are useful?
This argument can extended for unordered multisets as well, what differentiates then from using a vector and what advantages and disadvantages does it provide?
Because you don't have to store single-element objects in a multi-set. You're thinking of storing something like a string in a multi-set. But that's not what it's made for. You can have any struct you want, and make the comparison be with a single element in the struct.
For example:
In this naive "phone book" entry, there's no reason to have a single entry per name in a phone book. There might be many. So you make a
multiset
ofPhoneBookEntry
, and you make the comparator be byname
. This way, you can have multiple phone numbers with the same name.Now you might think that a map is more suitable for this, sure. But this is just an example. If you have a structure where you don't need a key/value but you need the search properties of a set with multiple elements per key, you use a multiset.