This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/13342] New: hash_map doesn't support std::string keys
- From: "kgirard at connect dot carleton dot ca" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 7 Dec 2003 17:32:24 -0000
- Subject: [Bug libstdc++/13342] New: hash_map doesn't support std::string keys
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
Overview Description:
The GNU extension hash_map class doesn't support using std::strings for keys. I
think it should support a common class like std::string
Steps to Reproduce:
I compiled this:
#include <string>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
int main()
{
hash_map<string, int> hm;
hm["January"] = 30;
return 0;
}
with the following:
g++ hashtest.cpp
Actual Results:
Gcc gave me the following error
...<snip>....
/usr/include/c++/3.3/ext/stl_hashtable.h:514: error: no match for call to `(
const __gnu_cxx::hash<std::string>) (const std::basic_string<char,
std::char_traits<char>, std::allocator<char> >&)'
Expected Results:
Successful Compile
Solution:
Add
template<> struct hash<std::string>
{
size_t operator()(const std::string& __x) const
{
return __stl_hash_string(__x.c_str());
}
};
to ext/stl_hash_fun.h
--
Summary: hash_map doesn't support std::string keys
Product: gcc
Version: 3.3.3
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: libstdc++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: kgirard at connect dot carleton dot ca
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13342