Evaluation of expressions and the comma operator
Lutger
lutger.blijdestijn at gmail.com
Mon Aug 21 11:08:44 PDT 2006
I have a basic, perhaps even dumb question that came up with the awesome
new implicit conversion of expressions to delegates:
In comma seperated expressions, (how) is the result of evaluation
defined? For example does (a, b) always yields the value of b? I expect
so, but I want to be sure.
Maybe some code is clearer, I was toying around to do this:
void main()
{
int a = 0;
int b = 1;
int c = 0;
// Prints a fibbonaci sequence, is this legal?
writefln( generate(10, ( c = (a + b), a = b, b = c) ) );
}
T[] generate(T)(int count, T delegate() dg)
{
T[] array;
array.length = count;
foreach(inout val; array)
val = dg();
return array;
}
More information about the Digitalmars-d-learn
mailing list