]> git.tdb.fi Git - libs/core.git/blobdiff - source/core/maputils.h
maputils.h: add insert_unique function
[libs/core.git] / source / core / maputils.h
index 1a7c0ae6ce8e952d1ab9b10113e47172dc4b3136..1b36c69569b6973992d381c7d39060e412341c89 100644 (file)
@@ -33,6 +33,15 @@ const typename T::mapped_type &get_item(const T &map, const typename T::key_type
        return i->second;
 }
 
+template<typename T>
+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