Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions std/experimental/allocator/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -1612,18 +1612,18 @@ lengths = static array containing the size of each dimension
Returns:
An N-dimensional array with individual elements of type T.
*/
auto makeMultidimensionalArray(uint n, T, Allocator)(auto ref Allocator alloc, size_t[n] lengths)
auto makeMultidimensionalArray(T, Allocator, size_t n)(auto ref Allocator alloc, size_t[n] lengths...)
{
static if (n == 1)
{
return makeArray!T(alloc, lengths[0]);
}
else
{
alias E = typeof(makeMultidimensionalArray!(n - 1, T)(alloc, lengths[1..$]));
alias E = typeof(makeMultidimensionalArray!(T, Allocator, n - 1)(alloc, lengths[1 .. $]));
auto ret = makeArray!E(alloc, lengths[0]);
foreach (ref e; ret)
e = makeMultidimensionalArray!(n - 1, T)(alloc, lengths[1..$]);
e = makeMultidimensionalArray!(T, Allocator, n - 1)(alloc, lengths[1 .. $]);
return ret;
}
}
Expand All @@ -1633,8 +1633,7 @@ auto makeMultidimensionalArray(uint n, T, Allocator)(auto ref Allocator alloc, s
{
import std.experimental.allocator.mallocator : Mallocator;

size_t[3] dimArray = [2, 3, 6];
auto mArray = Mallocator.instance.makeMultidimensionalArray!(dimArray.length, int)(dimArray);
auto mArray = Mallocator.instance.makeMultidimensionalArray!int(2, 3, 6);

// deallocate when exiting scope
scope(exit)
Expand All @@ -1660,7 +1659,7 @@ T = element type of an element of the multidimensional array
alloc = the allocator used for getting memory
array = the multidimensional array that is to be deallocated
*/
void disposeMultidimensionalArray(Allocator, T)(auto ref Allocator alloc, T[] array)
void disposeMultidimensionalArray(T, Allocator)(auto ref Allocator alloc, T[] array)
{
static if (isArray!T)
{
Expand Down Expand Up @@ -1720,8 +1719,7 @@ void disposeMultidimensionalArray(Allocator, T)(auto ref Allocator alloc, T[] ar

TestAllocator allocator;

size_t[5] a = [2, 3, 6, 7, 2];
auto mArray = allocator.makeMultidimensionalArray!(a.length, int)(a);
auto mArray = allocator.makeMultidimensionalArray!int(2, 3, 5, 6, 7, 2);

allocator.disposeMultidimensionalArray(mArray);
}
Expand Down