aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/corelib/tools/stlutils.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/corelib/tools/stlutils.h')
-rw-r--r--src/lib/corelib/tools/stlutils.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/lib/corelib/tools/stlutils.h b/src/lib/corelib/tools/stlutils.h
index 63b9c098e..1b6d7278f 100644
--- a/src/lib/corelib/tools/stlutils.h
+++ b/src/lib/corelib/tools/stlutils.h
@@ -75,6 +75,17 @@ bool containsKey(const C &container, const typename C::key_type &v)
return container.find(v) != end;
}
+template <class C>
+typename C::mapped_type mapValue(
+ const C &container,
+ const typename C::key_type &key,
+ const typename C::mapped_type &value = typename C::mapped_type())
+{
+ const auto end = container.cend();
+ const auto it = container.find(key);
+ return it != end ? it->second : value;
+}
+
template <typename C>
bool removeOne(C &container, const typename C::value_type &v)
{