[ create a new paste ] login | about

Project: ncu
Link: http://ncu.codepad.org/XcgLMGVa    [ raw code | output | fork ]

GiM - D, pasted on Sep 2:
import tango.io.Stdout;

char toupper(char letter)
{
    if (letter >= 'a' && letter <= 'z')
        return letter-32;
    else
        return letter;
}

template synthesize(alias T)
{
    const char[] synthesize = (typeof(T).stringof ~ " get" ~
            toupper(T.stringof[0]) ~ T.stringof[1..$] ~
            "() { return " ~ T.stringof ~ "; }\nvoid set" ~
            toupper(T.stringof[0]) ~ T.stringof[1..$] ~
            "(" ~ typeof(T).stringof ~ " v) { " ~
            T.stringof ~ " = v; }");

}

class Xmple
{
    int value;
    mixin (synthesize!(value));
}

class Foo
{
    int value;
    mixin (synthesize!(value));
}
void main()
{
    auto x = new Xmple;
    auto y = new Foo;

    x.setValue = 66;
    y.setValue = 77;

    Stdout ( x.getValue ).newline;
    Stdout ( y.getValue ).newline;
}


Output:
1
2
66
77


Create a new paste based on this one


Comments: