mirror of
https://github.com/aantron/better-enums.git
synced 2025-12-06 16:56:42 +08:00
Another approach to specialize the hash easier.
This commit is contained in:
parent
8a118fc294
commit
8aa4bffb22
23
enum.h
23
enum.h
@ -949,16 +949,6 @@ operator >>(std::basic_istream<Char, Traits>& stream, Enum &value) \
|
|||||||
stream.setstate(std::basic_istream<Char, Traits>::failbit); \
|
stream.setstate(std::basic_istream<Char, Traits>::failbit); \
|
||||||
\
|
\
|
||||||
return stream; \
|
return stream; \
|
||||||
} \
|
|
||||||
\
|
|
||||||
namespace std { \
|
|
||||||
template <> struct hash<Enum> \
|
|
||||||
{ \
|
|
||||||
size_t operator()(const Enum &x) const \
|
|
||||||
{ \
|
|
||||||
return std::hash<size_t>()(x._to_index()); \
|
|
||||||
} \
|
|
||||||
}; \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1293,4 +1283,17 @@ BETTER_ENUMS_CONSTEXPR_ map<Enum, T> make_map(T (*f)(Enum))
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef BETTER_ENUMS_DECLARE_STD_HASH
|
||||||
|
#define BETTER_ENUMS_DECLARE_STD_HASH(type) \
|
||||||
|
namespace std { \
|
||||||
|
template <> struct hash<type> \
|
||||||
|
{ \
|
||||||
|
size_t operator()(const type &x) const \
|
||||||
|
{ \
|
||||||
|
return std::hash<size_t>()(x._to_index()); \
|
||||||
|
} \
|
||||||
|
}; \
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // #ifndef BETTER_ENUMS_ENUM_H
|
#endif // #ifndef BETTER_ENUMS_ENUM_H
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user