On Tuesday, 13 June 2017 at 19:31:28 UTC, jmh530 wrote:
On Sunday, 11 December 2016 at 02:17:18 UTC, Mike Parker wrote:
What are properties if not "getters" and "setters"? From the
original post: "It would generate 2 methods "num": one to set
num_ and one to get its value."
Two methods named "num". No "get" or "set" in sight.
Sorry to bump, but it also isn't hard to use mixins to write
more generic get/set.
import std.stdio : writeln;
private int a;
private int b;
void set(string variable)(int x) @property
mixin(variable ~ " = x;");
int get(string variable)() @property
I suppose the errors will be more cryptic, since you don't check
if the string referers to an existing member.
You provide only get/set that return by value. So you may need to
generate getters/setters for const values, for ref values, for
const ref values... And it would result in much more code for