www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - mixin templates as ailas paramters

reply Nicholas Wilson <iamthewilsonator hotmail.com> writes:
Is there any reason why

mixin template Foo(T)
{

}

Struct Bar(ailas a)
{
     mixin a!int
}

doesn't work?
It gives an error saying that mixin templates are not normal 
templates.
I hacked around this by making Bar take an enumeration and then 
"static switch"ing on it to select the correct mixin template, 
but that makes the set of mixins i can pass it closed.

It needs to be a mixin template because I need to access Bar's 
this from inside Foo.
Nov 24 2016
parent reply ketmar <ketmar ketmar.no-ip.org> writes:
On Friday, 25 November 2016 at 00:43:25 UTC, Nicholas Wilson 
wrote:

works like a charm:


mixin template Foo(T) {
   int z = 42;
}

auto Bar(alias a) () {
   mixin a!int;
   return z;
}

void main () {
   writeln(Bar!Foo);
}
Nov 24 2016
parent Nicholas Wilson <iamthewilsonator hotmail.com> writes:
On Friday, 25 November 2016 at 01:08:38 UTC, ketmar wrote:
 On Friday, 25 November 2016 at 00:43:25 UTC, Nicholas Wilson 
 wrote:

 works like a charm:


 mixin template Foo(T) {
   int z = 42;
 }

 auto Bar(alias a) () {
   mixin a!int;
   return z;
 }

 void main () {
   writeln(Bar!Foo);
 }
Hmm, maybe i was trying to do Bar!Foo!int ...
Nov 24 2016