mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2026-07-26 00:45:35 +00:00
Codechange: introduce transparent hash lookup for strings
This commit is contained in:
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user