Marcus Kwok wrote:
breck <br******@comcast.net> wrote: I'm having trouble with hash_set's insert. It's not supposed to allow
the same element to be insert more than once, but this is what is
happening for me. My question is, what function does it use to compare
elements to see if it's already in set? Is it the EqualKey struct? The
== operator for the element it contains?
I don't know about hash_set, but if it's anything like std::set or
std::map then by default is uses operator< for the comparison, unless
you specify otherwise.
Probably it doesn't use operator< since a hash_set has no notion of
sorted keys in the way that std::set and its cousins do.
Since hash_set is not standard C++ this is implementation dependent. If
you use the SGI implementation, and your question suggests that you do,
then yes the EqualKey function object determines whether the keys are
equal. By default this is std::equal_to<Key> which in turn uses
operator== to test for equality.