Reference Tuples

Jarrett Billingsley jarrett.billingsley at gmail.com
Wed Oct 8 19:47:54 PDT 2008


On Wed, Oct 8, 2008 at 9:49 PM, dsimcha <dsimcha at yahoo.com> wrote:
> I'm trying to do some deep metaprogramming magic in D2, and an issue that I
> can't seem to get around is that I can't find a way to get a tuple of
> struct/class fields, or something similarly useful, with reference semantics.  Ex:
>
> struct S {
>    uint foo = 1;
> }
>
> void main() {
>    S s;
>    foreach(element; s.tupleof)
>         element = 2;
>    writeln(s.foo);  //Still 1.
> }

A simple workaround for this case is

foreach(i, element; s.tupleof)
    s.tupleof[i] = 2;

but I would have expected the 'ref' version to work.



More information about the Digitalmars-d mailing list