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(); }
T
A partial solution would be something like this:
mixin template makeProperty(T, string name, alias func) {
enum p = makeUnnamedProperty!(T, func);
mixin("enum %s = p;".format(name)); // or alias
}
however now the parent namespace is polluted with "p", is there
any way to
On Wednesday, 17 December 2014 at 01:14:36 UTC, aldanor wrote:
A partial solution would be something like this:
mixin template makeProperty(T, string name, alias func) {
enum p = makeUnnamedProperty!(T, func);
mixin("enum %s = p;".format(name)); // or alias
}
however now
On Wednesday, 17 December 2014 at 01:39:07 UTC, anonymous wrote:
But if you want to avoid `p`, just do the substitution:
mixin template makeProperty(T, string name, alias func) {
mixin("enum %s = makeUnnamedProperty!(T,
func);".format(name)); // or alias
}
Thanks, that looks
On Wednesday, 17 December 2014 at 01:49:14 UTC, aldanor wrote:
Wonder if this is doable within a single mixin template without
using makeUnnamedProperty?
Sure, straight forward:
mixin template makeProperty(T, string name, alias func) {
mixin("T %s() @property { return func();
}
On Wednesday, 17 December 2014 at 02:12:52 UTC, anonymous wrote:
Sure, straight forward:
mixin template makeProperty(T, string name, alias func) {
mixin("T %s() @property { return func();
}".format(name));
}
Indeed... thanks! Just one thing that I find confusing here -- h
On Wed, 17 Dec 2014 02:34:15 +
aldanor via Digitalmars-d-learn
wrote:
> On Wednesday, 17 December 2014 at 02:12:52 UTC, anonymous wrote:
> > Sure, straight forward:
> >
> > mixin template makeProperty(T, string name, alias func) {
> > mixin("T %s() @property { return func();
>
On Wednesday, 17 December 2014 at 02:34:16 UTC, aldanor wrote:
On Wednesday, 17 December 2014 at 02:12:52 UTC, anonymous wrote:
Sure, straight forward:
mixin template makeProperty(T, string name, alias func) {
mixin("T %s() @property { return func();
}".format(name));
}
Ind
On Wednesday, 17 December 2014 at 12:49:10 UTC, anonymous wrote:
As far as I understand, the string mixin is resolved first, and
then the template mixin takes place. So the progression is
somewhat like this (pseudo code):
mixin makeProperty!(int, "foo", f);
/* Replace "makeProperty" with i
On Wednesday, 17 December 2014 at 15:40:25 UTC, aldanor wrote:
On Wednesday, 17 December 2014 at 12:49:10 UTC, anonymous wrote:
[...]
As to if there were `T` or `func` in the target scope, they'd
be
shadowed by the template parameters, no matter if there's a
string mixin or not.
That makes sen
10 matches
Mail list logo