]> git.tdb.fi Git - libs/core.git/blobdiff - source/core/maputils.h
Add no-throw destructors to exception classes that were lacking one
[libs/core.git] / source / core / maputils.h
index 1a7c0ae6ce8e952d1ab9b10113e47172dc4b3136..9548714658d806fad41614357bc0e60fa8444cdf 100644 (file)
@@ -10,6 +10,7 @@ class key_error: public std::runtime_error
 {
 public:
        key_error(const std::type_info &);
+       ~key_error() throw() { }
 };
 
 
@@ -33,6 +34,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