hash.h: helper function for hashing scoped & unscoped enums

This commit is contained in:
Moritz Bunkus 2015-03-26 18:21:36 +01:00
parent 7b3b1d3ffc
commit d5819ce546

29
src/common/hash.h Normal file
View File

@ -0,0 +1,29 @@
/*
mkvmerge -- utility for splicing together matroska files
from component media subtypes
Distributed under the GPL v2
see the file COPYING for details
or visit http://www.gnu.org/copyleft/gpl.html
Hash/unordered map helper functions
Written by Moritz Bunkus <moritz@bunkus.org>.
*/
#ifndef MTX_COMMON_HASH_H
#define MTX_COMMON_HASH_H
#include <functional>
// Support for hashing all scoped and unscoped enums via their
// underlying type.
template<typename Tkey>
struct std::hash {
std::size_t operator()(Tkey const &key) const {
using T = typename std::underlying_type<Tkey>::type;
return std::hash<T>()(static_cast<T>(key));
}
};
#endif // MTX_COMMON_HASH_H