Codechange: introduce transparent hash lookup for strings

This commit is contained in:
Rubidium
2025-04-27 17:57:42 +02:00
committed by rubidium42
parent 7bbf380931
commit 4e3e3d5be6
3 changed files with 15 additions and 4 deletions
+10
View File
@@ -59,4 +59,14 @@ using StringValidationSettings = EnumBitSet<StringValidationSetting, uint8_t>;
/** Type for a list of strings. */
typedef std::vector<std::string> StringList;
/** Helper to provide transparent hashing for string types in e.g. std::unordered_map. */
struct StringHash {
using hash_type = std::hash<std::string_view>;
using is_transparent = void;
std::size_t operator()(const char *str) const { return hash_type{}(str); }
std::size_t operator()(std::string_view str) const { return hash_type{}(str); }
std::size_t operator()(const std::string &str) const { return hash_type{}(str); }
};
#endif /* STRING_TYPE_H */