diff --git a/libs/util/include/psemek/util/hash_table.hpp b/libs/util/include/psemek/util/hash_table.hpp index b35cf3ee..63e9149d 100644 --- a/libs/util/include/psemek/util/hash_table.hpp +++ b/libs/util/include/psemek/util/hash_table.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -437,6 +438,32 @@ namespace psemek::util return impl_.end(); } + template + Value & operator[] (Key1 const & key) + { + if (auto it = find(key); it != end()) + return it->second; + return insert({Key(key), Value{}}).first->second; + } + + template + Value & at(Key1 const & key) + { + auto it = find(key); + if (it == end()) + throw util::key_error{key}; + return it->second; + } + + template + Value const & at(Key1 const & key) const + { + auto it = find(key); + if (it == end()) + throw util::key_error{key}; + return it->second; + } + void clear() { impl_.clear();