Skip to content

Provide generic hasher for enum classes #22

Open

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

  1. scheibel commented on Jan 20, 2017

    @scheibel
    MemberAuthor

    I think we'll need a new submodule name for such a class (and many to follow).
    It's a explicit extension to standard library concepts with the contexts hash and enum class.
    Any ideas? @sbusch42 @cgcostume

  2. scheibel commented on Feb 2, 2017

    @scheibel
    MemberAuthor

    Seems like C++14 and 17 added support for this with their respective stdlibs. However, as we develop cppassist using C++11 I think we have to provide fallback implementations for older compilers and stdlibs.
    We will have to find code to detect whether hashing is already provided by the stdlib.

  3. cgcostume commented on Oct 23, 2018

    @cgcostume
    Member

    is this required? and we should think about switching to C++14?

  4. scheibel commented on Oct 23, 2018

    @scheibel
    MemberAuthor

    I think an upgrade to C++14 becomes feasible, soon.
    Fortunately, such an upgrade would imply the removal of some more implementations in cppassist.

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