Wow, I figured out a trick. Check it out, two modules:

1. fieldwrite.d:
module fieldwrite;

import std.string;
import std.stdio;
import std.conv;

mixin template field(string T)
{
    struct FieldTemp
    {
        this(string str)
        {
            writefln(str ~ " = %s", mixin(T));
        }
    }

    FieldTemp fieldTemp = FieldTemp(T);
}

2. driver.d:

import std.stdio;
import fieldwrite;

struct S
{
    int x;
    int y;
}

void main()
{
    S s;
    s.x = 1;
    s.y = 2;

    mixin field!"s.x";
    mixin field!"s.y";
}

Reply via email to