]> git.tdb.fi Git - libs/core.git/blobdiff - source/core/maputils.h
Add a function to remove an item from a map, checking for existence
[libs/core.git] / source / core / maputils.h
index 0f863b46fdf7dea307f251be4823a4e63cdcbc4e..ecee0fbea45955dbf9bef8f8bf296bb387b3e414 100644 (file)
@@ -83,6 +83,15 @@ const typename T::iterator insert_unique(T &map, const typename T::key_type &key
        return map.insert(typename T::value_type(key, item)).first;
 }
 
+template<typename T>
+void remove_existing(T &map, const typename T::key_type &key)
+{
+       if(!map.count(key))
+               throw key_error(key);
+
+       map.erase(key);
+}
+
 } // namespace Msp
 
 #endif