From 320a6dc3c78f9b06fa19dd26ebea04c3c5a8b6a2 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 27 Aug 2023 13:59:18 +0300 Subject: [PATCH] Add a moving overload of insert_unique --- source/core/maputils.h | 9 +++++++++ 1 file changed, 9 insertions(+) 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) { -- 2.45.2