X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fcore%2Fmaputils.h;h=f5faa1271a2e1317523767c5e9c3e6a858792027;hp=ecee0fbea45955dbf9bef8f8bf296bb387b3e414;hb=f24e7b96e76b63c9b9b8a6bce4c7a9db64276ea8;hpb=85c6b143c9b85ce09ee4f3cb842d3ae006b7a6fe diff --git a/source/core/maputils.h b/source/core/maputils.h index ecee0fb..f5faa12 100644 --- a/source/core/maputils.h +++ b/source/core/maputils.h @@ -57,7 +57,7 @@ private: template typename T::mapped_type &get_item(T &map, const typename T::key_type &key) { - typename T::iterator i = map.find(key); + auto i = map.find(key); if(i==map.end()) throw key_error(key); @@ -67,20 +67,26 @@ typename T::mapped_type &get_item(T &map, const typename T::key_type &key) template const typename T::mapped_type &get_item(const T &map, const typename T::key_type &key) { - typename T::const_iterator i = map.find(key); + auto i = map.find(key); if(i==map.end()) throw key_error(key); return i->second; } +template +D *get_item(const T &map, const typename T::key_type &key) +{ + return dynamic_cast(get_item(map, key)); +} + template -const typename T::iterator insert_unique(T &map, const typename T::key_type &key, const typename T::mapped_type &item) +typename T::iterator insert_unique(T &map, const typename T::key_type &key, const typename T::mapped_type &item) { if(map.count(key)) throw key_error(key); - return map.insert(typename T::value_type(key, item)).first; + return map.insert(std::make_pair(key, item)).first; } template