From 79482ba7aea1b79c7a310c940cc0292532ef3bcb Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 25 Jul 2011 11:02:05 +0300 Subject: [PATCH] maputils.h: add insert_unique function --- source/core/maputils.h | 9 +++++++++ 1 file changed, 9 insertions(+) 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 -- 2.45.2