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/string_map.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/string_map.cpp') diff --git a/src/string_map.cpp b/src/string_map.cpp index 7a446937a..09e125800 100644 --- a/src/string_map.cpp +++ b/src/string_map.cpp @@ -54,6 +54,10 @@ template T * string_map_get (StringMap *h, char co template T * string_map_get (StringMap *h, String const &key); template T * string_map_get (StringMap *h, StringHashKey const &key); +template T & string_map_must_get (StringMap *h, char const *key); +template T & string_map_must_get (StringMap *h, String const &key); +template T & string_map_must_get (StringMap *h, StringHashKey const &key); + template void string_map_set (StringMap *h, StringHashKey const &key, T const &value); template void string_map_set (StringMap *h, String const &key, T const &value); template void string_map_set (StringMap *h, char const *key, T const &value); @@ -187,6 +191,23 @@ gb_inline T *string_map_get(StringMap *h, char const *key) { return string_map_get(h, string_hash_string(make_string_c(key))); } +template +T &string_map_must_get(StringMap *h, StringHashKey const &key) { + isize index = string_map__find(h, key).entry_index; + GB_ASSERT(index >= 0); + return h->entries[index].value; +} + +template +gb_inline T &string_map_must_get(StringMap *h, String const &key) { + return string_map_must_get(h, string_hash_string(key)); +} + +template +gb_inline T &string_map_must_get(StringMap *h, char const *key) { + return string_map_must_get(h, string_hash_string(make_string_c(key))); +} + template void string_map_set(StringMap *h, StringHashKey const &key, T const &value) { isize index; -- cgit v1.2.3