Is [] mandatory for array operations?

Michel Fortin michel.fortin at
Thu May 6 19:52:29 PDT 2010

On 2010-05-06 22:46:42 -0400, Michel Fortin <michel.fortin at> said:

> That said, I'd expect the compiler to call sin(y) only once, so it'd be 
> more like that:
> 	auto sinY = sin(y);
> 	for(int i = 0; i < x.length; i++) {
> 		x[i] = sinY[i];
> 	}

And I'd expect that because in the expression "x[] = sin(y)[]" none of 
sin's argument are part of an array operation. Calling a function 
repeatedly should only happen when one of its arguments can change 
between iterations (and possibly only pure functions should be allowed 
to be called repeatedly through array ops).

Michel Fortin
michel.fortin at

More information about the Digitalmars-d mailing list