cppassist
cppassist copied to clipboard
Provide generic hasher for enum classes
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> {};
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
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.
is this required? and we should think about switching to C++14?
I think an upgrade to C++14 becomes feasible, soon. Fortunately, such an upgrade would imply the removal of some more implementations in cppassist.