[Bf-blender-cvs] [f908ff1ccdf] master: BLI: simplify adding an arbitrary value to a resource container

Jacques Lucke noreply at git.blender.org
Thu Feb 25 17:17:52 CET 2021


Commit: f908ff1ccdfb0133e1797877363f063b9daa696c
Author: Jacques Lucke
Date:   Thu Feb 25 17:17:45 2021 +0100
Branches: master
https://developer.blender.org/rBf908ff1ccdfb0133e1797877363f063b9daa696c

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.

===================================================================

M	source/blender/blenlib/BLI_resource_collector.hh

===================================================================

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<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.



More information about the Bf-blender-cvs mailing list