Referring to alias parameters in a mixin template
aldanor via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Dec 16 16:47:57 PST 2014
Would something like this be possible at all? A hypothetical
mixin template
mixin template makeProperty(T, string name, alias func) {
...
}
that could be called like this:
makeProperty!(int, "foo", f)
and would generate code like
int @property foo() { return f(); }
This is a very simplified example of what I'm trying to do, but
I'm a bit stuck at this point -- if I'm generating the code as a
string, how do I know how to refer to "func" alias (traits
identifier / fullyQualifiedName just don't cut it for a lot of
cases)? For one, thing, it could be an anonymous delegate like {
return 0; } or symbol from another module or anything else. This
is obviously doable if "func" is a string that gets mixed in, but
what if it is an alias?
Without the "name" part, one could sure use a simple template:
template makeUnnamedProperty(T, alias func) {
T makeUnnamedProperty() @property { return func(); }
}
and then this works...
alias foo = makeUnnamedProperty!(int, f);
However, how does the one go about templating this when "foo" is
a (compile-time) string?
Wonder if I'm missing something...
Thanks.
More information about the Digitalmars-d-learn
mailing list