STL hash_set problem, SGI impl

T

Timo Qvist

Hi, I'm a bit new to STL and really new to SGI's hash_set implementation and
I've having problem
instantiating a hash_set with a custom hash function, I could really use
some help sifting through g++ (v3.3.3)
error message on this particular problem.

I want a hash_set with class pointers as the hashed type, my class is
simply called Transition, the following code
doesn't work;

using namespace __gnu_cxx;

typedef struct _HashFunc : public unary_function<Transition *, size_t > {
size_t operator()( const Transition *t ) const {
return t->getID();
}
} HashFunc;

void foo( Transition *trans ) {
hash_set< Transition *, hash<HashFunc> > my_hashset; // This far the
compiler doesn't complain...
myhashset.insert( trans ); // however, adding this instatiation causes
the following error;

}

/usr/include/c++/3.3.3/ext/stl_hashtable.h: In member function `size_t
__gnu_cxx::hashtable<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey,
_Alloc>::_M_bkt_num_key(const _Key&, unsigned int) const [with _Val =
Transition*, _Key = Transition*, _HashFcn = __gnu_cxx::hash<HashFunc>,
_ExtractKey = std::_Identity<Transition*>, _EqualKey =
std::equal_to<Transition*>, _Alloc = std::allocator<Transition*>]':
/usr/include/c++/3.3.3/ext/stl_hashtable.h:519: instantiated from `size_t
__gnu_cxx::hashtable<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey,
_Alloc>::_M_bkt_num(const _Val&, unsigned int) const [with _Val =
Transition*, _Key = Transition*, _HashFcn = __gnu_cxx::hash<HashFunc>,
_ExtractKey = std::_Identity<Transition*>, _EqualKey =
std::equal_to<Transition*>, _Alloc = std::allocator<Transition*>]'
/usr/include/c++/3.3.3/ext/stl_hashtable.h:884: instantiated from `void
__gnu_cxx::hashtable<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey,
_Alloc>::resize(unsigned int) [with _Val = Transition*, _Key = Transition*,
_HashFcn = __gnu_cxx::hash<HashFunc>, _ExtractKey =
std::_Identity<Transition*>, _EqualKey = std::equal_to<Transition*>, _Alloc
= std::allocator<Transition*>]'
/usr/include/c++/3.3.3/ext/stl_hashtable.h:378: instantiated from
`std::pair<__gnu_cxx::_Hashtable_iterator<_Val, _Key, _HashFcn, _ExtractKey,
_EqualKey, _Alloc>, bool> __gnu_cxx::hashtable<_Val, _Key, _HashFcn,
_ExtractKey, _EqualKey, _Alloc>::insert_unique(const _Val&) [with _Val =
Transition*, _Key = Transition*, _HashFcn = __gnu_cxx::hash<HashFunc>,
_ExtractKey = std::_Identity<Transition*>, _EqualKey =
std::equal_to<Transition*>, _Alloc = std::allocator<Transition*>]'
/usr/include/c++/3.3.3/ext/hash_set:175: instantiated from
`std::pair<typename __gnu_cxx::hashtable<_Value, _Value, _HashFcn,
std::_Identity<_Key>, _EqualKey, _Alloc>::const_iterator, bool>
__gnu_cxx::hash_set<_Value, _HashFcn, _EqualKey, _Alloc>::insert(typename
__gnu_cxx::hashtable<_Value, _Value, _HashFcn, std::_Identity<_Key>,
_EqualKey, _Alloc>::value_type&) [with _Value = Transition*, _HashFcn =
__gnu_cxx::hash<HashFunc>, _EqualKey = std::equal_to<Transition*>, _Alloc =
std::allocator<Transition*>]'
net.cpp:328: instantiated from here
/usr/include/c++/3.3.3/ext/stl_hashtable.h:514: error: no match for call to
`(
const __gnu_cxx::hash<HashFunc>) (Transition* const&)'

Ok, so I've figured out that somewhere deep down in the template we try and
call the HashFunc operator() and we cant find a match,
I just cant fix the HashFunc functor with the correct types for this to
work?

Or am I missing something?

/tq
 
V

Victor Bazarov

Timo said:
Hi, I'm a bit new to STL and really new to SGI's hash_set implementation and
I've having problem
instantiating a hash_set with a custom hash function, I could really use
some help sifting through g++ (v3.3.3)
error message on this particular problem.

I want a hash_set with class pointers as the hashed type, my class is
simply called Transition, the following code
doesn't work;

using namespace __gnu_cxx;

typedef struct _HashFunc : public unary_function<Transition *, size_t > {
size_t operator()( const Transition *t ) const {

Try changing this to

size_t operator()(Transition * const & t ) const {

return t->getID();
}
} HashFunc;

void foo( Transition *trans ) {
hash_set< Transition *, hash<HashFunc> > my_hashset; // This far the
compiler doesn't complain...
myhashset.insert( trans ); // however, adding this instatiation causes
the following error;

}

[...]
/usr/include/c++/3.3.3/ext/stl_hashtable.h:514: error: no match for call to
`(
const __gnu_cxx::hash<HashFunc>) (Transition* const&)'
^^^^^^^^^^^^^^^^^^
That's the type it expects to find
Ok, so I've figured out that somewhere deep down in the template we try and
call the HashFunc operator() and we cant find a match,
I just cant fix the HashFunc functor with the correct types for this to
work?

Or am I missing something?

I guess so...

V
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top