From: Mikko Rasa Date: Mon, 25 Jul 2011 08:02:05 +0000 (+0300) Subject: maputils.h: add insert_unique function X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=commitdiff_plain;h=79482ba7aea1b79c7a310c940cc0292532ef3bcb;ds=sidebyside maputils.h: add insert_unique function --- diff --git a/source/core/maputils.h b/source/core/maputils.h index 1a7c0ae..1b36c69 100644 --- a/source/core/maputils.h +++ b/source/core/maputils.h @@ -33,6 +33,15 @@ const typename T::mapped_type &get_item(const T &map, const typename T::key_type return i->second; } +template +const 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(typeid(T)); + + return map.insert(typename T::value_type(key, item)).first; +} + } // namespace Msp #endif