Reference Tuples
Max Samukha
samukha at voliacable.com.removethis
Wed Oct 8 23:21:59 PDT 2008
On Thu, 9 Oct 2008 01:49:36 +0000 (UTC), 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.
>}
>
>The obvious thing, which I already tried was:
>
>foreach(ref element; s.tupleof) //Doesn't compile.
>
>Is there a way to get a tuple representation of a class/struct such that I can
>change the fields of the class/struct through the tuple representation, or
>should I file this as an enhancement?
Possible workaround:
struct S {
uint foo = 1;
}
void main() {
S s;
foreach(i, element; s.tupleof)
s.tupleof[i] = 2;
writeln(s.foo);
}
But you file it as enhancement anyway.
More information about the Digitalmars-d
mailing list