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:
Diffstat (limited to 'source/blender/blenlib/BLI_linear_allocator.hh')
-rw-r--r--source/blender/blenlib/BLI_linear_allocator.hh15
1 files changed, 15 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_linear_allocator.hh b/source/blender/blenlib/BLI_linear_allocator.hh
index bd883c1de16..87361d412cb 100644
--- a/source/blender/blenlib/BLI_linear_allocator.hh
+++ b/source/blender/blenlib/BLI_linear_allocator.hh
@@ -149,6 +149,21 @@ template<typename Allocator = GuardedAllocator> class LinearAllocator : NonCopya
}
/**
+ * Construct multiple instances of a type in an array. The constructor of is called with the
+ * given arguments. The caller is responsible for calling the destructor (and not `delete`) on
+ * the constructed elements.
+ */
+ template<typename T, typename... Args>
+ MutableSpan<T> construct_array(int64_t size, Args &&... args)
+ {
+ MutableSpan<T> array = this->allocate_array<T>(size);
+ for (const int64_t i : IndexRange(size)) {
+ new (&array[i]) T(std::forward<Args>(args)...);
+ }
+ return array;
+ }
+
+ /**
* Copy the given array into a memory buffer provided by this allocator.
*/
template<typename T> MutableSpan<T> construct_array_copy(Span<T> src)