M
Mark
Hi,
I'm trying to use hash_map (gcc 3.2.2) with a std::string as the key. It
will compile if I use <map> but I get a bunch of template compile errors
when I change it to hash_map. Any suggestions? My program and the errors
are below...
#include <ext/hash_map>
#include <string>
using namespace std;
__gnu_cxx::hash_map<string, int> storage;
int main()
{
pair<string, int> item("blah", 1);
storage.insert(item);
}
When compiled I get the following:
g++ hm.cpp -o hm
/usr/include/c++/3.2.2/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 =
std:
air<const std::string, int>, _Key = std::string, _HashFcn =
__gnu_cxx::hash<std::string>, _ExtractKey = std::_Select1st<std:
air<const
std::string, int> >, _EqualKey = std::equal_to<std::string>, _Alloc =
std::allocator<int>]':
/usr/include/c++/3.2.2/ext/stl_hashtable.h:522: instantiated from `size_t
__gnu_cxx::hashtable<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey,
_Alloc>::_M_bkt_num(const _Val&, unsigned int) const [with _Val =
std:
air<const std::string, int>, _Key = std::string, _HashFcn =
__gnu_cxx::hash<std::string>, _ExtractKey = std::_Select1st<std:
air<const
std::string, int> >, _EqualKey = std::equal_to<std::string>, _Alloc =
std::allocator<int>]'
/usr/include/c++/3.2.2/ext/stl_hashtable.h:887: instantiated from `void
__gnu_cxx::hashtable<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey,
_Alloc>::resize(unsigned int) [with _Val = std:
air<const std::string,
int>, _Key = std::string, _HashFcn = __gnu_cxx::hash<std::string>,
_ExtractKey = std::_Select1st<std:
air<const std::string, int> >, _EqualKey
= std::equal_to<std::string>, _Alloc = std::allocator<int>]'
/usr/include/c++/3.2.2/ext/stl_hashtable.h:381: instantiated from
`std:
air<__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 =
std:
air<const std::string, int>, _Key = std::string, _HashFcn =
__gnu_cxx::hash<std::string>, _ExtractKey = std::_Select1st<std:
air<const
std::string, int> >, _EqualKey = std::equal_to<std::string>, _Alloc =
std::allocator<int>]'
/usr/include/c++/3.2.2/ext/hash_map:171: instantiated from
`std:
air<__gnu_cxx::hashtable<std:
air<const _Key, _Tp>, _Key, _HashFcn,
std::_Select1st<std:
air<const _Key, _Tp> >, _EqualKey, _Alloc>::iterator,
bool> __gnu_cxx::hash_map<_Key, _Tp, _HashFcn, _EqualKey,
_Alloc>::insert(__gnu_cxx::hashtable<std:
air<const _Key, _Tp>, _Key,
_HashFcn, std::_Select1st<std:
air<const _Key, _Tp> >, _EqualKey,
_Alloc>::value_type&) [with _Key = std::string, _Tp = int, _HashFcn =
__gnu_cxx::hash<std::string>, _EqualKey = std::equal_to<std::string>, _Alloc
= std::allocator<int>]'
hm.cpp:14: instantiated from here
/usr/include/c++/3.2.2/ext/stl_hashtable.h:517: no match for call to `(const
__gnu_cxx::hash<std::string>) (const std::basic_string<char,
std::char_traits<char>, std::allocator<char> >&)'
make: *** [hm] Error 1
I'm trying to use hash_map (gcc 3.2.2) with a std::string as the key. It
will compile if I use <map> but I get a bunch of template compile errors
when I change it to hash_map. Any suggestions? My program and the errors
are below...
#include <ext/hash_map>
#include <string>
using namespace std;
__gnu_cxx::hash_map<string, int> storage;
int main()
{
pair<string, int> item("blah", 1);
storage.insert(item);
}
When compiled I get the following:
g++ hm.cpp -o hm
/usr/include/c++/3.2.2/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 =
std:
__gnu_cxx::hash<std::string>, _ExtractKey = std::_Select1st<std:
std::string, int> >, _EqualKey = std::equal_to<std::string>, _Alloc =
std::allocator<int>]':
/usr/include/c++/3.2.2/ext/stl_hashtable.h:522: instantiated from `size_t
__gnu_cxx::hashtable<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey,
_Alloc>::_M_bkt_num(const _Val&, unsigned int) const [with _Val =
std:
__gnu_cxx::hash<std::string>, _ExtractKey = std::_Select1st<std:
std::string, int> >, _EqualKey = std::equal_to<std::string>, _Alloc =
std::allocator<int>]'
/usr/include/c++/3.2.2/ext/stl_hashtable.h:887: instantiated from `void
__gnu_cxx::hashtable<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey,
_Alloc>::resize(unsigned int) [with _Val = std:
int>, _Key = std::string, _HashFcn = __gnu_cxx::hash<std::string>,
_ExtractKey = std::_Select1st<std:
= std::equal_to<std::string>, _Alloc = std::allocator<int>]'
/usr/include/c++/3.2.2/ext/stl_hashtable.h:381: instantiated from
`std:
_EqualKey, _Alloc>, bool> __gnu_cxx::hashtable<_Val, _Key, _HashFcn,
_ExtractKey, _EqualKey, _Alloc>::insert_unique(const _Val&) [with _Val =
std:
__gnu_cxx::hash<std::string>, _ExtractKey = std::_Select1st<std:
std::string, int> >, _EqualKey = std::equal_to<std::string>, _Alloc =
std::allocator<int>]'
/usr/include/c++/3.2.2/ext/hash_map:171: instantiated from
`std:
std::_Select1st<std:
bool> __gnu_cxx::hash_map<_Key, _Tp, _HashFcn, _EqualKey,
_Alloc>::insert(__gnu_cxx::hashtable<std:
_HashFcn, std::_Select1st<std:
_Alloc>::value_type&) [with _Key = std::string, _Tp = int, _HashFcn =
__gnu_cxx::hash<std::string>, _EqualKey = std::equal_to<std::string>, _Alloc
= std::allocator<int>]'
hm.cpp:14: instantiated from here
/usr/include/c++/3.2.2/ext/stl_hashtable.h:517: no match for call to `(const
__gnu_cxx::hash<std::string>) (const std::basic_string<char,
std::char_traits<char>, std::allocator<char> >&)'
make: *** [hm] Error 1