diff --git a/m-dict.h b/m-dict.h index c43def43..529dc496 100644 --- a/m-dict.h +++ b/m-dict.h @@ -244,7 +244,7 @@ } \ \ static inline value_type * \ - M_C(name, _get)(const dict_t map, const key_type key) \ + M_C(name, _get)(const dict_t map, key_type const key) \ { \ DICTI_CONTRACT(name, map); \ size_t hash = M_GET_HASH key_oplist (key); \ @@ -263,6 +263,12 @@ return NULL; \ } \ \ + static inline value_type const * \ + M_C(name, _cget)(const dict_t map, key_type const key) \ + { \ + return M_CONST_CAST(value_type, M_C(name,_get)(map,key)); \ + } \ + \ static inline void \ M_C(name, _int_resize_up)(dict_t map) \ { \ @@ -836,6 +842,12 @@ typedef enum { return NULL; \ } \ \ + static inline value_type const * \ + M_C(name, _cget)(const dict_t map, key_type const key) \ + { \ + return M_CONST_CAST(value_type, M_C(name,_get)(map,key)); \ + } \ + \ M_IF_DEBUG( \ static inline bool \ M_C(name,_int_control_after_resize)(const dict_t h) \ diff --git a/tests/test-mdict.c b/tests/test-mdict.c index 17ff9dba..e3ce65cb 100644 --- a/tests/test-mdict.c +++ b/tests/test-mdict.c @@ -266,6 +266,8 @@ static void test1(void) FILE *f = fopen("dict.txt", "rt"); if (!f) abort(); dict_str_set_at(dict, STRING_CTE("LICENCE"), STRING_CTE("BSD3")); + assert(string_equal_p(*dict_str_cget(dict, STRING_CTE("LICENCE")), STRING_CTE("BSD3"))); + while (!feof(f) && !ferror(f)) { string_fgets(key, f, STRING_READ_PURE_LINE); size_t idx = string_search_char(key, ':');