STL hash_set problem, SGI impl

Discussion in 'C++' started by Timo Qvist, Nov 18, 2004.

  1. Timo Qvist

    Timo Qvist Guest

    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
    Timo Qvist, Nov 18, 2004
    #1
    1. Advertising

  2. Timo Qvist wrote:
    > 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
    Victor Bazarov, Nov 18, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chaman Singh

    SGI STL

    Chaman Singh, Apr 12, 2004, in forum: C++
    Replies:
    1
    Views:
    501
    Christopher Benson-Manica
    Apr 13, 2004
  2. Swamy Muddu

    STL map impl. in C

    Swamy Muddu, Jul 23, 2003, in forum: C Programming
    Replies:
    2
    Views:
    384
    Mr. 4X
    Jul 23, 2003
  3. zl2k
    Replies:
    2
    Views:
    551
  4. Pierre Couderc
    Replies:
    2
    Views:
    5,279
  5. eric
    Replies:
    3
    Views:
    1,290
    Michael DOUBEZ
    Jul 12, 2011
Loading...

Share This Page