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