This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: 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:26:12 +0000
- Subject: Re: hash_set equal function
- References: <200503042007.17948.mvc@netcabo.pt>
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>