From: Mikko Rasa Date: Wed, 6 Nov 2013 09:23:31 +0000 (+0200) Subject: Add a function to remove an item from a map, checking for existence X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=85c6b143c9b85ce09ee4f3cb842d3ae006b7a6fe;p=libs%2Fcore.git Add a function to remove an item from a map, checking for existence --- diff --git a/source/core/maputils.h b/source/core/maputils.h index 0f863b4..ecee0fb 100644 --- a/source/core/maputils.h +++ b/source/core/maputils.h @@ -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 +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