static assert

rm roel.mathys at gmail.com
Sat Oct 21 01:40:46 PDT 2006


a few questions,
1| the doc on the website is not 100% clear for me.
Is it possible to have an optional const char[] argument in a static assert?
2| what am I doing wrong in the code below? Why doesn't the static
assert fire? (remark that when putting the static assert in a separate
mixin I can get it to work)


roel

======================================================================

template itoa(int n)
{
	static if (n<0)
		const char[] itoa = "-" ~ itoa!(-n);
	else static if (n<10)
		const char[] itoa = "0123456789"[n..n+1];
	else
		const char[] itoa = itoa!(n/10) ~ "0123456789"[n%10];
}

template Factor(int n:0)
{
	const int Factor = 1;
}

template Factor(int n)
{
	pragma(msg, itoa!(n));
	static assert(n>0);
	const int Factor = n * Factor!(n-1);
}


import std.stdio;
void main()
{
	writefln(Factor!(-5));
}



More information about the Digitalmars-d-learn mailing list