Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2020-04-28 14:55:36 +0300
committerJacques Lucke <jacques@blender.org>2020-04-28 14:55:36 +0300
commit9c65ac73112f1a0f837cb50a2a446129acf19081 (patch)
tree7ef58bff4aeae04e8dafde734ca5e2b5ac0f99e1 /source
parent2c6022108070b53f0293aaba177bc63d184161c7 (diff)
BLI: add Map.lookup_or_add_default method
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenlib/BLI_map.hh13
1 files changed, 13 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_map.hh b/source/blender/blenlib/BLI_map.hh
index eb9c6372995..ea5e5da4099 100644
--- a/source/blender/blenlib/BLI_map.hh
+++ b/source/blender/blenlib/BLI_map.hh
@@ -408,6 +408,19 @@ class Map {
}
/**
+ * Return the value that corresponds to the given key.
+ * If it does not exist yet, insert a new default constructed value and return that.
+ */
+ ValueT &lookup_or_add_default(const KeyT &key)
+ {
+ return this->lookup_or_add(key, []() { return ValueT(); });
+ }
+ ValueT &lookup_or_add_default(const KeyT &&key)
+ {
+ return this->lookup_or_add(std::move(key), []() { return ValueT(); });
+ }
+
+ /**
* Get the number of elements in the map.
*/
uint32_t size() const