This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
hash_set equal function
- From: Marco Correia <mvc at netcabo dot pt>
- To: libstdc++ at gcc dot gnu dot org
- Date: Fri, 4 Mar 2005 20:07:17 +0000
- Subject: hash_set equal function
Hi,
Could anyone please tell me why the user defined equal function never gets
called in the following code example?
#include <iostream>
#include <sstream>
#include <ext/hash_set>
using namespace std;
using namespace __gnu_cxx;
struct base
{};
struct derived : public base
{};
struct hash_fun
{
size_t operator()(const base* e) const
{ return (size_t)e; }
};
struct equal_fun
{
size_t operator()(const base* e1, const base* e2) const
{
cout << "here" << endl; // this never gets printed
return 1;
}
};
int main()
{
hash_set<base*,hash_fun,equal_fun> m;
derived* d1 = new derived();
derived* d2 = new derived();
m.insert(d1);
cout << (m.find(d2)==m.end()) << endl; // should call
equal_fun::operator() ?
}
Thanks!
Marco
PS: Please email me directly since I'm not subscribed.
-- Marco Correia <mvc@netcabo.pt>