Created
May 28, 2015 18:25
-
-
Save m-alvarez/1f5ded8386b4dc2c3831 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std.stdio; | |
import std.algorithm; | |
mixin template VarDecl(T, alias string VarName) { | |
mixin (`private T `~VarName~`;`); | |
mixin (`T get_`~VarName~`() { return this.`~VarName~`; }`); | |
mixin (`void set_`~VarName~`(T value) { this.`~VarName~` = value; }`); | |
} | |
class Klass { | |
mixin VarDecl!(int, "age"); | |
mixin VarDecl!(int, "height"); | |
mixin VarDecl!(string, "name"); | |
} | |
int main() { | |
auto k = new Klass; | |
k.set_age(100); | |
auto age = k.get_age(); | |
printf("%d\n", k.get_age()); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment