hash_set help

B

breck

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?

Thanks in advance,
-- Breck Fresen
 
M

Marcus Kwok

breck said:
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.
 
M

Mark P

Marcus said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top