[ox/std] Fix non-const HashMap::at

This commit is contained in:
Gary Talent 2021-04-01 21:57:26 -05:00
parent 7bbd7bfdb5
commit 86f0e1ca08

View File

@ -133,14 +133,18 @@ T &HashMap<K, T>::operator[](K k) {
template<typename K, typename T> template<typename K, typename T>
Result<T*> HashMap<K, T>::at(K k) { Result<T*> HashMap<K, T>::at(K k) {
return &operator[](k); auto p = access(m_pairs, k);
if (!p) {
return {nullptr, OxError(1, "Value not found for key")};
}
return &p->value;
} }
template<typename K, typename T> template<typename K, typename T>
Result<const T*> HashMap<K, T>::at(K k) const { Result<const T*> HashMap<K, T>::at(K k) const {
auto p = access(m_pairs, k); auto p = access(m_pairs, k);
if (!p) { if (!p) {
return {nullptr, OxError(1)}; return {nullptr, OxError(1, "Value not found for key")};
} }
return &p->value; return &p->value;
} }