#pragma once #include #include /** MapFindPtr usage: if (T* value = MapFindPtr(myMap, someKey) { Cout << *value; } */ template inline auto MapFindPtr(Map& map, const K& key) { auto i = map.find(key); return (i == map.end() ? nullptr : &i->second); } template inline auto MapFindPtr(const Map& map, const K& key) { auto i = map.find(key); return (i == map.end() ? nullptr : &i->second); } /** helper for THashMap/TMap */ template struct TMapOps { template inline auto FindPtr(const K& key) { return MapFindPtr(static_cast(*this), key); } template inline auto FindPtr(const K& key) const { return MapFindPtr(static_cast(*this), key); } template inline auto Value(const K& key, DefaultValue&& defaultValue) const { auto found = FindPtr(key); return found ? *found : std::forward(defaultValue); } template inline const V& ValueRef(const K& key, V& defaultValue) const { static_assert(std::is_same, typename Derived::mapped_type>::value, "Passed default value must have the same type as the underlying map's mapped_type."); if (auto found = FindPtr(key)) { return *found; } return defaultValue; } template inline const V& ValueRef(const K& key, V&& defaultValue) const = delete; };