Skip to content

Instantly share code, notes, and snippets.

@m-alvarez
Created May 28, 2015 18:25
Show Gist options
  • Save m-alvarez/1f5ded8386b4dc2c3831 to your computer and use it in GitHub Desktop.
Save m-alvarez/1f5ded8386b4dc2c3831 to your computer and use it in GitHub Desktop.
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