Thread overview |
---|
February 25, 2010 compile time opCall array assignment | ||||
---|---|---|---|---|
| ||||
struct S{ int[2] arr = 0; static S opCall( int i1_, int i2_) { S res = void; res.arr[0] = i1_; res.arr[1] = i2_; return res; } } const S CS= S(0,0); Why can't this be evaluated at compile time? (And how do I fix it :)) |
February 26, 2010 Re: compile time opCall array assignment | ||||
---|---|---|---|---|
| ||||
Posted in reply to strtr | strtr wrote:
> struct S{
> int[2] arr = 0;
>
> static S opCall( int i1_, int i2_) {
> S res = void;
> res.arr[0] = i1_;
> res.arr[1] = i2_;
> return res;
> }
> }
>
> const S CS= S(0,0);
>
> Why can't this be evaluated at compile time?
> (And how do I fix it :))
>
Because expressions of the form a.b[i]= c aren't yet supported in CTFE.
It will work in a couple of compiler releases from now.
Workaround:
int[2] x;
x[0]=i1_;
x[1]=i2_;
res.arr=x;
|
February 26, 2010 Re: compile time opCall array assignment | ||||
---|---|---|---|---|
| ||||
Posted in reply to Don | Don Wrote: > Because expressions of the form a.b[i]= c aren't yet supported in CTFE. It will work in a couple of compiler releases from now. Only D2, or D1 as well? > Workaround: > int[2] x; > x[0]=i1_; > x[1]=i2_; > res.arr=x; > :) |
February 26, 2010 Re: compile time opCall array assignment | ||||
---|---|---|---|---|
| ||||
Posted in reply to strtr | strtr wrote: > Don Wrote: > >> Because expressions of the form a.b[i]= c aren't yet supported in CTFE. >> It will work in a couple of compiler releases from now. > Only D2, or D1 as well? Both. > >> Workaround: >> int[2] x; >> x[0]=i1_; >> x[1]=i2_; >> res.arr=x; >> > :) |
Copyright © 1999-2021 by the D Language Foundation