From 4b831dbdddb92c4dbe32dc7b2a6a647febddf5dc Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sun, 4 Jul 2021 12:37:21 +0100 Subject: Try `try` and `or_else` built-in procedures with operators `try` and `try else` --- src/map.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/map.cpp') diff --git a/src/map.cpp b/src/map.cpp index 85836fccb..fc23c9aec 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -69,6 +69,7 @@ struct Map { template void map_init (Map *h, gbAllocator a, isize capacity = 16); template void map_destroy (Map *h); template T * map_get (Map *h, HashKey const &key); +template T & map_must_get (Map *h, HashKey const &key); template void map_set (Map *h, HashKey const &key, T const &value); template void map_remove (Map *h, HashKey const &key); template void map_clear (Map *h); @@ -202,6 +203,13 @@ T *map_get(Map *h, HashKey const &key) { return nullptr; } +template +T &map_must_get(Map *h, HashKey const &key) { + isize index = map__find(h, key).entry_index; + GB_ASSERT(index >= 0); + return h->entries[index].value; +} + template void map_set(Map *h, HashKey const &key, T const &value) { isize index; -- cgit v1.2.3