From f908ff1ccdfb0133e1797877363f063b9daa696c Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Thu, 25 Feb 2021 17:17:45 +0100 Subject: 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. --- source/blender/blenlib/BLI_resource_collector.hh | 9 +++++++++ 1 file changed, 9 insertions(+) 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 @@ -107,6 +107,15 @@ class ResourceCollector : NonCopyable, NonMovable { m_resources.append(data); } + /** + * Construct an object with the same value in the ResourceCollector and return a reference to the + * new value. + */ + template T &add_value(T &&value, const char *name) + { + return this->construct(name, std::forward(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. -- cgit v1.2.3