A static array contained inside a struct is not accessible during CTFE. Because of this, it seems impossible (since some versions) to define compile-time constants of such structures (for example tuple vectors or matrices).
---
struct S {
int arr[1];
this(int x){
arr[0] = x; // (this.arr[0u]) = x cannot be evaluated at compile time
}
}
immutable S s_constant = S(1); // Error: cannot evaluate __ctmp1.this(1) at compile time
---
Comment #1 by clugdbug — 2010-02-26T07:37:38Z
a.b[i]=c; isn't implemented in CTFE yet, but a.b=c; is, so I'm downgrading from blocker. (It's still high priority, though).
Workaround:
struct S {
int arr[1];
this(int x){
int[1] z = x;
arr = z;
}
}
Comment #2 by sludwig — 2010-02-27T03:44:47Z
Unfortunately, the workaround also errors out with (although I did not check a current svn build):
test.d(6): Error: this.arr[] = cast(const(int[]))x cannot be evaluated at compile time
But this gave me finally another idea, which seems to work:
struct test {
int[1] f;
this(int x){
int[] dst = f;
dst[0] = x;
}
}
[Now off to some code porting and finally trying out the recent features... ;-)]