Try try and or_else built-in procedures with operators try and try else

This commit is contained in:
gingerBill
2021-07-04 12:37:21 +01:00
parent a01d6dcea7
commit 4b831dbddd
11 changed files with 335 additions and 307 deletions

View File

@@ -69,6 +69,7 @@ struct Map {
template <typename T> void map_init (Map<T> *h, gbAllocator a, isize capacity = 16);
template <typename T> void map_destroy (Map<T> *h);
template <typename T> T * map_get (Map<T> *h, HashKey const &key);
template <typename T> T & map_must_get (Map<T> *h, HashKey const &key);
template <typename T> void map_set (Map<T> *h, HashKey const &key, T const &value);
template <typename T> void map_remove (Map<T> *h, HashKey const &key);
template <typename T> void map_clear (Map<T> *h);
@@ -202,6 +203,13 @@ T *map_get(Map<T> *h, HashKey const &key) {
return nullptr;
}
template <typename T>
T &map_must_get(Map<T> *h, HashKey const &key) {
isize index = map__find(h, key).entry_index;
GB_ASSERT(index >= 0);
return h->entries[index].value;
}
template <typename T>
void map_set(Map<T> *h, HashKey const &key, T const &value) {
isize index;