[Issue 13556] inconsistent 'new' syntax for arrays
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sat May 30 15:39:56 PDT 2015
https://issues.dlang.org/show_bug.cgi?id=13556
--- Comment #9 from Ketmar Dark <ketmar at ketmar.no-ip.org> ---
(In reply to dennis.m.ritchie from comment #7)
> I suggest to implement such a syntax for declaring multidimensional arrays:
>
> auto array = new int[11](4, 8, 6, 13 /* .... The length of the other
> subarrays on request */);
you can do almost the same with templates.
auto DNew(T, A...) () if (A.length > 0) {
template A2S(A...) {
import std.conv : to;
static if (A.length == 0)
enum A2S = "";
else
enum A2S = to!string(A[0])~","~A2S!(A[1..$]);
}
import std.array : replicate;
return mixin("new "~T.stringof~"[]".replicate(A.length)~"("~A2S!A~")");
}
void main () {
import std.stdio;
auto a = DNew!(int, 5, 6, 7);
a[2][3][4] = 42;
writeln(a[2][3][]);
}
--
More information about the Digitalmars-d-bugs
mailing list