Skip to content

Provide generic hasher for enum classes #22

Description

@scheibel

Possible implementation:

template<typename EnumClass>
struct EnumClassHash
{
    std::hash<unsigned char>::result_type operator()(
        const EnumClass & arg) const
    {
        static std::hash<unsigned char> hasher;
        return hasher(static_cast<unsigned char>(arg));
    }
};

Possible usage:

template <>
struct hash<MyEnumClass> : EnumClassHash<MyEnumClass> {};

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions