jeudi 3 décembre 2015

Class member pointer to std::hash

I want to have a pointer to an instance of std::hash<k_type> in my class HashMap but can't find the right syntax (k_type is defined in my template class), so I know that this:

std::hash<k_type> hash;
hash(k_type var);

And this are functionally equivalent: std::hash<k_type>()(k_type var);

What I've tried:

template<typename k_type>
class HashMap {
private:
    size_t (*hash_func__)(k_type);
public:
    void set_hash(size_t (*hash_func)(k_type) = nullptr) {
        if (nullptr == hash_func) {
            std::hash<k_type> hash;
            hash_func__ = &hash;
        } else {
            // Deal with other hash funcs, works fine
        }
    }
}

This gives me incompatible pointer types, which given the above equivalent noted, doesn't make sense to me. Can someone please explain why, if std::hash is returning something of type size_t this wouldn't work?

Thanks!

Aucun commentaire:

Enregistrer un commentaire