www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - compile time opCall array assignment

reply strtr <strtr spam.com> writes:
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 :))
Feb 25 2010
parent reply Don <nospam nospam.com> writes:
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 :))
 

It will work in a couple of compiler releases from now. Workaround: int[2] x; x[0]=i1_; x[1]=i2_; res.arr=x;
Feb 25 2010
parent reply strtr <strtr spam.com> writes:
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.

 Workaround:
 int[2] x;
 x[0]=i1_;
 x[1]=i2_;
 res.arr=x;
 

Feb 26 2010
parent Don <nospam nospam.com> writes:
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.


Both.
 
 Workaround:
 int[2] x;
 x[0]=i1_;
 x[1]=i2_;
 res.arr=x;


Feb 26 2010