Referring to alias parameters in a mixin template

anonymous via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Dec 16 17:39:06 PST 2014


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 the parent namespace is polluted with "p", is there 
> any way to hide it away and/or avoid it?

The polution isn't too bad. Mixed-in symbols are second class. A
symbol not from a mixin would win, and multiple mixed-in `p`s
would only conflict on use.

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
      }


More information about the Digitalmars-d-learn mailing list