lundi 27 avril 2015

Specializing std::hash for templated Key

I was trying to specialize hash for my own type, a templated key.

I was basing it off cppreference.

I get the compile error "The C++ Standard doesn't provide a hash for this type". I figure I just did it wrong. Could the compiler even support this kind of template?

namespace std {
    template<typename SType, typename AType, typename PType>
    struct MyKey {
        const SType from;
        const AType consume;
        const PType pop;
    };

    template<typename SType, typename AType, typename PType>
    struct hash<MyKey<SType, AType, PType>> {
        size_t operator ()(MyKey const &key) {
            std::hash<SType>()(key.from);
            std::hash<AType>()(key.consume);
            std::hash<PType>()(key.pop);
        }
    };
}

Aucun commentaire:

Enregistrer un commentaire