> A indirect solution may be adding the multiset items to a
> set and then get the set size..
> But I wonder if there is a direct way of getting the unique
> items number
STL's multisets do not have any special support for this, i.e. they
don't spend time / use extra memory to track the unique keys while the
values are being inserted. Therefore, you must either proactively
maintain your own count while inserting and erasing from the multiset
(e.g. insert: check if the multiset includes the key, add 1 to
unique_keys counter if not). Otherwise, you will need to step through
the container to count unique keys... using upper_bound() will skip to
the next key, which just might be faster than a simple iteration, but
could also be slower (may depend on average number of times a key
repeats).
Cheers,
Tony