www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Mixin template parameter that is an undefined variable

reply tcak <1ltkrs+3wyh1ow7kzn1k sharklasers.com> writes:
[code]
mixin template Test(alias a){
	int a;
}

void main(){
	mixin Test!blah;
}
[/code]

Compiler says it doesn't know about "blah". My purpose is to
define the parameter as a variable. Is that possible?
Oct 23 2015
parent John Colvin <john.loughran.colvin gmail.com> writes:
On Friday, 23 October 2015 at 12:22:49 UTC, tcak wrote:
 [code]
 mixin template Test(alias a){
 	int a;
 }

 void main(){
 	mixin Test!blah;
 }
 [/code]

 Compiler says it doesn't know about "blah". My purpose is to
 define the parameter as a variable. Is that possible?
you would have to use a string. mixin template Test(string a) { mixin(`int ` ~ a ~ `;`); } void main() { mixin Test!"blah"; mixin Test!q{blah2}; }
Oct 23 2015