Skip to content

Commit

Permalink
Merge pull request dlang#5155 from wilzbach/fix-allocator-api
Browse files Browse the repository at this point in the history
Allocator: fix experimental makeMultidimensionalArray API
merged-on-behalf-of: Sebastian Wilzbach <[email protected]>
  • Loading branch information
dlang-bot authored Feb 22, 2017
2 parents 77b37fd + 64a0814 commit f795add
Showing 1 changed file with 6 additions and 8 deletions.
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

0 comments on commit f795add

Please sign in to comment.