diff options
author | Jacques Lucke <jacques@blender.org> | 2021-03-07 16:24:52 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2021-03-07 16:24:52 +0300 |
commit | 649916f0983e4c59201672e6e28dcc7ae1f655b2 (patch) | |
tree | f8caa573963f0af1897b25cbda1352c5ea7474a1 /source/blender/blenlib/BLI_linear_allocator.hh | |
parent | 456d3cc85e9f408341b12eb0d4f2c3a925855e8c (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_linear_allocator.hh')
-rw-r--r-- | source/blender/blenlib/BLI_linear_allocator.hh | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/source/blender/blenlib/BLI_linear_allocator.hh b/source/blender/blenlib/BLI_linear_allocator.hh index 11022a03d69..0bf4ad194e1 100644 --- a/source/blender/blenlib/BLI_linear_allocator.hh +++ b/source/blender/blenlib/BLI_linear_allocator.hh @@ -118,14 +118,14 @@ template<typename Allocator = GuardedAllocator> class LinearAllocator : NonCopya * * Arguments passed to this method will be forwarded to the constructor of T. * - * You must not call `delete` on the returned pointer. - * Instead, the destruct has to be called explicitly. + * You must not call `delete` on the returned value. + * Instead, only the destructor has to be called. */ - template<typename T, typename... Args> T *construct(Args &&... args) + template<typename T, typename... Args> destruct_ptr<T> construct(Args &&... args) { void *buffer = this->allocate(sizeof(T), alignof(T)); T *value = new (buffer) T(std::forward<Args>(args)...); - return value; + return destruct_ptr<T>(value); } /** |