Fixes functions for getting underlying std map from StringViewDictionary
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Deukhoofd 2022-05-16 16:43:52 +02:00
parent e0c16b772c
commit e2ea281de1
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
1 changed files with 8 additions and 9 deletions

View File

@ -11,13 +11,11 @@ namespace ArbUt {
/// @brief Wrapper around unordered_map, allowing safer access and adding several helper methods.
template <class ValueT> class StringViewDictionary {
private:
struct StringViewHash
{
struct StringViewHash {
using hash_type = std::hash<StringView>;
using is_transparent = void;
size_t operator()(const char* str) const { return hash_type{}(str); }
size_t operator()(const char* str) const { return hash_type{}(str); }
size_t operator()(StringView const& str) const { return hash_type{}(str); }
size_t operator()(u32 hash) const { return hash; }
};
@ -86,7 +84,6 @@ namespace ArbUt {
/// @brief Gets a value from the dictionary using the direct hash of the key.
[[nodiscard]] inline const ValueT& GetFromHash(u32 hash) const { return _map.find(hash)->second; }
/// @brief Try to get an item from the dictionary using a key. Returns false if no item is found, and out will
/// not be touched in that case.
inline std::optional<std::reference_wrapper<const ValueT>> TryGet(const StringView& key) const noexcept {
@ -97,8 +94,8 @@ namespace ArbUt {
return std::ref(find->second);
}
/// @brief Try to get an item from the dictionary using the hash of a key. Returns false if no item is found, and out will
/// not be touched in that case.
/// @brief Try to get an item from the dictionary using the hash of a key. Returns false if no item is found,
/// and out will not be touched in that case.
inline std::optional<std::reference_wrapper<const ValueT>> TryGet(u32 hash) const noexcept {
const auto& find = _map.find(hash);
if (find == _map.end()) {
@ -132,9 +129,11 @@ namespace ArbUt {
const_iterator end() const { return _map.end(); }
/// @brief returns the backing unordered_map.
const std::unordered_map<StringView, ValueT>& GetStdMap() const noexcept { return _map; }
const std::unordered_map<StringView, ValueT, StringViewHash, std::equal_to<>>& GetStdMap() const noexcept {
return _map;
}
/// @brief returns the backing unordered_map.
std::unordered_map<StringView, ValueT>& GetStdMap() noexcept { return _map; }
std::unordered_map<StringView, ValueT, StringViewHash, std::equal_to<>>& GetStdMap() noexcept { return _map; }
};
}