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-03-07 16:24:52 +0300
committerJacques Lucke <jacques@blender.org>2021-03-07 16:24:52 +0300
commit649916f0983e4c59201672e6e28dcc7ae1f655b2 (patch)
treef8caa573963f0af1897b25cbda1352c5ea7474a1 /source/blender/blenlib/BLI_resource_collector.hh
parent456d3cc85e9f408341b12eb0d4f2c3a925855e8c (diff)
BLI: make it harder to forget to destruct a value
Instead of returning a raw pointer, `LinearAllocator.construct(...)` now returns a `destruct_ptr`, which is similar to `unique_ptr`, but does not deallocate the memory and only calls the destructor instead.
Diffstat (limited to 'source/blender/blenlib/BLI_resource_collector.hh')
-rw-r--r--source/blender/blenlib/BLI_resource_collector.hh7
1 files changed, 4 insertions, 3 deletions
diff --git a/source/blender/blenlib/BLI_resource_collector.hh b/source/blender/blenlib/BLI_resource_collector.hh
index ecae9b8c682..70804ceb1f1 100644
--- a/source/blender/blenlib/BLI_resource_collector.hh
+++ b/source/blender/blenlib/BLI_resource_collector.hh
@@ -130,9 +130,10 @@ class ResourceCollector : NonCopyable, NonMovable {
*/
template<typename T, typename... Args> T &construct(const char *name, Args &&... args)
{
- T *value = m_allocator.construct<T>(std::forward<Args>(args)...);
- this->add(destruct_ptr<T>(value), name);
- return *value;
+ destruct_ptr<T> value_ptr = m_allocator.construct<T>(std::forward<Args>(args)...);
+ T &value_ref = *value_ptr;
+ this->add(std::move(value_ptr), name);
+ return value_ref;
}
/**