I have a hash table class. It has a template parameter hashFunction:
#include <string>
template<class KeyType> using hashFunction_t = size_t(size_t, const KeyType&);
template< class KeyType, class ValueType, int nHashGroups,
hashFunction_t<KeyType> hashFunction >
class HashTable
{
};
class Entity
{
//djb2
size_t stringHash(size_t nGroups, const std::string& key)
{
unsigned long hash = 5381;
const char* str = key.c_str();
int c = 0;
while (c = *str++)
hash = ((hash << 5) + hash) + c;
return hash % nGroups;
}
HashTable <std::string, int, 10, stringHash> ht;
};
int main()
{
Entity{};
}
I would prefer to hide stringHash function inside the Entity class as a private function but doing that gives me an error:
Error (active) E0458 argument of type
"size_t (Entity::*)(size_t nGroups, const std::string &key)"
is incompatible with template parameter of type
"hashFunction_t<std::string> *"
How can I do this?