From: Mikko Rasa Date: Sun, 27 Aug 2023 10:59:18 +0000 (+0300) Subject: Add a moving overload of insert_unique X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=320a6dc3c78f9b06fa19dd26ebea04c3c5a8b6a2;p=libs%2Fcore.git Add a moving overload of insert_unique --- diff --git a/source/core/maputils.h b/source/core/maputils.h index 9a72d4d..94947a1 100644 --- a/source/core/maputils.h +++ b/source/core/maputils.h @@ -90,6 +90,15 @@ typename T::iterator insert_unique(T &map, const typename T::key_type &key, cons return map.insert(std::make_pair(key, item)).first; } +template +typename T::iterator insert_unique(T &map, const typename T::key_type &key, typename T::mapped_type &&item) +{ + if(map.count(key)) + throw key_error(key); + + return map.insert(std::make_pair(key, std::move(item))).first; +} + template void remove_existing(T &map, const typename T::key_type &key) {