xxxxxxxxxx
/+dub.sdl:
dependency "automem" version="~>0.0.10"
+/
import std.stdio;
import automem;
import core.stdc.stdio;
void main()
{
import std.experimental.allocator.mallocator : Mallocator;
import std.algorithm : move;
struct Point
{
int x;
int y;
}
// the constructor can also take (size, init) or (size, range) values
auto arr = UniqueArray!(Point, Mallocator)(3);
const Point[3] expected1 = [Point(), Point(), Point()]; // because array literals aren't @nogc
assert(arr[] == expected1);
const Point[1] expected2 = [Point()];
arr.length = 1;
assert(*arr == expected2); //deferencing is the same as slicing all of it
arr ~= UniqueArray!(Point, Mallocator)(1, Point(6, 7));
const Point[2] expected3 = [Point(), Point(6, 7)];
assert(arr[] == expected3);
foreach (a; arr)
printf("%d,%d\n", a.x, a.y);
}