From 85c6b143c9b85ce09ee4f3cb842d3ae006b7a6fe Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 6 Nov 2013 11:23:31 +0200 Subject: [PATCH] Add a function to remove an item from a map, checking for existence --- source/core/maputils.h | 9 +++++++++ 1 file changed, 9 insertions(+) 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 -- 2.45.2