Struct hashable

Synopsis

#include <include/type_safe/strong_typedef.hpp>

template <class StrongTypedef>
struct hashable : std::hash<type_safe::underlying_type<StrongTypedef>>

Description

Inherit from it in the std::hash<StrongTypedef> specialization to make it hashable like the underlying type. See example/strong_typedef.cpp.

Mentioned in

Inheritance

Ancestors: std::hash< type_safe::underlying_type< StrongTypedef > >

Methods

operator()

Source

Lines 777-788 in include/type_safe/strong_typedef.hpp.

template <class StrongTypedef>
struct hashable : std::hash<type_safe::underlying_type<StrongTypedef>>
{
    using underlying_type = type_safe::underlying_type<StrongTypedef>;
    using underlying_hash = std::hash<underlying_type>;

    std::size_t operator()(const StrongTypedef& lhs) const
        noexcept(noexcept(underlying_hash{}(std::declval<underlying_type>())))
    {
        return underlying_hash{}(static_cast<const underlying_type&>(lhs));
    }
};





Add Discussion as Guest

Log in