inferred size for static array initialization
Erik Smith via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon May 2 10:17:56 PDT 2016
I tried to combine the two solutions (Basile with the wrapper,
Marco with the struct initializer support) but it didn't work.
The struct initializer is not a array literal (seems obvious
now). I might go with the 2nd but it's pretty heavy just to get
the size.
Thanks.
struct S {
int a, b;
}
auto toStaticArray(alias array)()
{
struct S { int a, b; }
immutable tab = {
static enum S[] s = array;
return cast(typeof(s[0])[s.length])s;
}();
return tab;
}
enum a = toStaticArray!([{1,2},{3,4}]); // error
More information about the Digitalmars-d-learn
mailing list