Referring to alias parameters in a mixin template

ketmar via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Dec 17 02:38:25 PST 2014


On Wed, 17 Dec 2014 02:34:15 +0000
aldanor via Digitalmars-d-learn <digitalmars-d-learn at 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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20141217/9ee34ccf/attachment-0001.sig>


More information about the Digitalmars-d-learn mailing list