How should this be done? (1.0)

Michael Coupland mcoupland at gmail.com
Mon Feb 4 21:49:50 PST 2008


The following doesn't work because I'm trying to use a template mixin 
like a string constant mixin, and you can't actually do calculations in 
a template like this. (You get "no identifier for declarator" errors on 
the assignment lines.) What is the Proper D Way to do this? (I'd rather 
not use a function that returns a struct; in C/C++ one would probably 
use a macro.) I considered a heredoc string and doing a proper textual 
mixin, but that feels like overkill...

	Michael

-----------------------------------------------

template CommonCalculations()
{
     bool commonBool1;
     bool commonBool2;
	
     {
         int LocalVal = SomeFn();
         commonBool1 = SomeOtherFunc();
	commonBool2 = AThirdFunction(LocalVal,commonBool1);
     }
};

// (...)

{
	mixin CommonCalculations!();
	// do stuff here with commonBool1 and commonBool2
}



More information about the Digitalmars-d-learn mailing list