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
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2021-02-25 19:17:45 +0300
committerJacques Lucke <jacques@blender.org>2021-02-25 19:17:45 +0300
commitf908ff1ccdfb0133e1797877363f063b9daa696c (patch)
tree17eecaead648344d6af9542f320822f12580a534
parent35df354e4aa4b1c848dfa0e1d80951e103caacea (diff)
BLI: simplify adding an arbitrary value to a resource container
With this is becomes easily possible to store a lambda in a resource collector so that it will be freed when the resource collector is freed.
-rw-r--r--source/blender/blenlib/BLI_resource_collector.hh9
1 files changed, 9 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_resource_collector.hh b/source/blender/blenlib/BLI_resource_collector.hh
index 20180f3b2c9..ecae9b8c682 100644
--- a/source/blender/blenlib/BLI_resource_collector.hh
+++ b/source/blender/blenlib/BLI_resource_collector.hh
@@ -108,6 +108,15 @@ class ResourceCollector : NonCopyable, NonMovable {
}
/**
+ * Construct an object with the same value in the ResourceCollector and return a reference to the
+ * new value.
+ */
+ template<typename T> T &add_value(T &&value, const char *name)
+ {
+ return this->construct<T>(name, std::forward<T>(value));
+ }
+
+ /**
* Returns a reference to a linear allocator that is owned by the ResourcesCollector. Memory
* allocated through this allocator will be freed when the collector is destructed.
*/