template const to compile-time function

Carlos Santander csantander619 at gmail.com
Tue Sep 4 08:25:03 PDT 2007


Currently I have this template:

template seqWrapper (char[] property, alias seq, alias array)
{
	const seqWrapper = typeof(array).stringof ~ " " ~ property ~ "()"
	"{"
	"if (" ~ array.stringof ~ ".length == 0)"
	"	" ~ array.stringof ~ " = seqToArray (" ~ seq.stringof ~ ");"
	"return " ~ array.stringof ~ ";"
	"}";
}

Which is simply used like this:

mixin (seqWrapper!("users", _list, _users));

And it works. But I was wondering if it was better to have it as a compile-time 
function, and if so, how it could be changed. I'm using D1.0, btw.

-- 
Carlos Santander Bernal


More information about the Digitalmars-d-learn mailing list