]> git.tdb.fi Git - libs/core.git/commitdiff
Add a function to remove an item from a map, checking for existence
authorMikko Rasa <tdb@tdb.fi>
Wed, 6 Nov 2013 09:23:31 +0000 (11:23 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 6 Nov 2013 09:24:28 +0000 (11:24 +0200)
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