hash_set equal function
Marco Correia
mvc@netcabo.pt
Fri Mar 4 20:26:00 GMT 2005
Please ignore the post, I found out the solution. Equal objects must have the
same hash value...
Marco
On Friday 04 March 2005 20:07, Marco Correia wrote:
> 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>
--
Marco Correia <mvc@netcabo.pt>
More information about the Libstdc++
mailing list