On 7 Apr., 18:13, sje...@gmail.com wrote:
I am new to boost, and to templates (feeling very comfortable with C).
I am trying to use boost hash tables where the keys are char *, like:
unordered_map<const char *, CMyclass *> myclass_map_t ;
Note: I have no experience with this new facility of the
boost trunk, but it seems that it reflects the current
specification of upcoming C++0x std::unordered_map (given
current compiler technologies, i.e. modulo rvalue references
where not available).
1. Couldnt figure so far, how do i set a hash function that works on
the string (and not on the pointer) ?
IMO hash functions on string-like entities belong to
the most popular use-cases of hashers. A simple way would
be to have a look at boost's implementation for std::string,
which effectively calls boost::hash_range. So you could provide
something like
#include <string.h>
struct CharArrayHashEqual : std::unary_function<const char*,
std::size_t>
{
std::size_t operator()(const char* s) const {
return boost::hash_range(s, strlen(s));
}
bool operator(const char* s1, const char* s2) const {
return strcmp(s1, s2) == 0;
}
[ comp.lang.c++.moderated. First time posters: Do this! ]