This code doesn't work!
----
auto test(ARGS...)()
{
int[ARGS.length] x;
return x;
}
void main(string[] args)
{
void func(){ }
auto t = test!(func)();
}
----
Results:
prog.d(3): Error: identifier 'length' of 'ARGS.length' is not defined
prog.d(3): Error: index is not a type or an expression
prog.d(10): Error: template instance prog.main.test!(func) error instantiating
Workaround is this:
----
size_t lengthof(ARGS...)()
{
return ARGS.length;
}
auto test(ARGS...)()
{
int[lengthof!(ARGS)()] x;
return x;
}
void main(string[] args)
{
void func(){ }
auto t = test!(func)();
}
----
Comment #1 by bearophile_hugs — 2010-09-19T17:44:54Z
Created attachment 764
Patch against dmd r680, fixes resolveHelper()
This patch fixes the reported issue and bug 2953 (D2). It passed dmd, druntime and phobos tests.
The patch also fixes the following problems:
--------------------
struct R
{
alias int T;
}
struct S
{
R r;
alias r this;
}
S.T x; // (10)
int[S.r.offsetof] y; // (11)
--------------------
% dmd -o- -c test.d
test.d(10): Error: S.T is used as a type
test.d(11): Error: no property 'offsetof' for type 'R'