From 4ff36a61ba263253dc1b1e15c922c2ecb95ecde5 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Wed, 28 Feb 2024 16:59:58 +0300 Subject: [PATCH] Add util::hash_map::operator[] --- libs/util/include/psemek/util/hash_table.hpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libs/util/include/psemek/util/hash_table.hpp b/libs/util/include/psemek/util/hash_table.hpp index 5fef85b0..83fac31c 100644 --- a/libs/util/include/psemek/util/hash_table.hpp +++ b/libs/util/include/psemek/util/hash_table.hpp @@ -475,6 +475,14 @@ namespace psemek::util return impl_.insert(std::move(value)); } + template + Value & operator[] (Key1 const & key) + { + if (auto it = find(key); it != end()) + return it->second; + return insert({Key(key), Value{}}).first->second; + } + template iterator find(Key1 const & key) const {