properties as lvalues

Ivan Kazmenko gassa at mail.ru
Sun May 14 02:18:31 PDT 2006


cschueler:
>Note: Properties currently cannot be the lvalue of an op=, ++, or -- operator. 
>This strikes me, as I thought this was very easy to do - just have the access
>function return a reference to the value. Oh wait, there are no references in D
>(at least I didn't find them in the specs)? I think C++ has explicit references
>for a reason, and this might be a hint why this is so.

There's another situation I'd like to have references for. Consider a
multi-sized array, with part of the program heavily working on a fixed part of
the array. In C++, one may write, for example:
-----
typedef int arr [4] [4]; // 2D array

arr a [4] [4]; // 4D array

int main (void)
{
int i, j, k, l, m;
for (i = 0; i < 4; i++)
for (j = 0; j < 4; j++)
{
arr & b = a[i][j]; // 2D array currently used
for (k = 0; k < 4; k++)
for (l = 0; l < 4; l++)
for (m = 0; m < 4; m++)
b[k][l] += b[(k + m) & 3][(l + m) & 3]; // no particular sense here :)
}
return 0;
}
-----
That works perfectly in C++ but I didn't find a way to achieve similar effect in
D. This could be another use of alias statement (most preferrable), or even with
statement (though it will probably look weird). But so far, it seems neither can
do the trick.

Ivan Kazmenko.



More information about the Digitalmars-d mailing list