makeMultidimensionalArray

Allocates a multidimensional array of elements of type T.

makeMultidimensionalArray
(
T
Allocator
size_t N
)
(
auto ref Allocator alloc
,
size_t[N] lengths...
)

Parameters

N

number of dimensions

T

element type of an element of the multidimensional arrat

alloc Allocator

the allocator used for getting memory

lengths size_t[N]

static array containing the size of each dimension

Return Value

Type: auto

An N-dimensional array with individual elements of type T.

Examples

1 import std.experimental.allocator.mallocator : Mallocator;
2 
3 auto mArray = Mallocator.instance.makeMultidimensionalArray!int(2, 3, 6);
4 
5 // deallocate when exiting scope
6 scope(exit)
7 {
8     Mallocator.instance.disposeMultidimensionalArray(mArray);
9 }
10 
11 assert(mArray.length == 2);
12 foreach (lvl2Array; mArray)
13 {
14     assert(lvl2Array.length == 3);
15     foreach (lvl3Array; lvl2Array)
16         assert(lvl3Array.length == 6);
17 }

Meta

Suggestion Box / Bug Report