On Wed, 17 Dec 2014 02:34:15 +0000 aldanor via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com> 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)); > > } > > Indeed... thanks! Just one thing that I find confusing here -- how > exactly do T and func resolve when this template is mixed in? > What if there was another local symbol named "func" in the target > scope? this is mixed inside the `makeProperty` template itself, not where you instantiated it. i.e. when compiler sees mixin, it not postponing it. so what you actually got is `makeProperty` template with `%s` substituted with `name`, and only then `makeProperty` is mixed at the place of it's instatiation.
signature.asc
Description: PGP signature