diff options
author | Jacques Lucke <jacques@blender.org> | 2020-04-28 14:55:36 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-04-28 14:55:36 +0300 |
commit | 9c65ac73112f1a0f837cb50a2a446129acf19081 (patch) | |
tree | 7ef58bff4aeae04e8dafde734ca5e2b5ac0f99e1 /source/blender/blenlib | |
parent | 2c6022108070b53f0293aaba177bc63d184161c7 (diff) |
BLI: add Map.lookup_or_add_default method
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_map.hh | 13 |
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 |