This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]