Dave wrote:
Hello NG,
Why would one not just always use std::multiset<> instead of std::set<> (and
similarly for maps)? Clearly, there must be tradeoffs to gain the ability
to have repeated keys. What are the tradeoffs?
I don't know for sure, but I definitely use the non-multi versions more
frequently. I think the code would be more complicated using multimaps
when maps do the job. For example, you don't get operator[].
Consider looking up a single element. In a map, it's either found or
not. In a multimap, if it's found, you still might need to check whether
there are others.
Consider storing a unique key-value pair. In a map you just do it. In a
multimap, you have to first look up and remove any existing matching keys.
-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.