some template questions

Don Clugston dac at nospam.com.au
Mon May 22 23:47:40 PDT 2006


BCS wrote:
> Two questions:
> 
> This is supposed to make a list of all numbers from 0 to i, can it be made to
> work, and if so how?

It doesn't work because D doesn't have array literals yet.
(But since D *does* have char[] and dchar[] literals, you can do some 
nasty casts to get the effect you want).

> template list(int i)
> {
> static if(i==0)
> int[] list = [0];
> else
> int[] list = list!(i-1) ~ i;	
> }
> 
> Should this hang or should the static assert kill it before it loops? (as of
> 0.157, it hangs)
> 
> template hang()
> {
> static assert(false);
> const int hang = hang!();
> }

The file below doesn't hang for me in DMD 0.156 Windows, it gives a 
sensible error message:
-----
template hang()
{
	static assert(0);
	const int hang = hang!();
}

const int x = hang!();
-----
If that it fails for you, enter it in Bugzilla as a regression or 
Linux-only bug.




More information about the Digitalmars-d-learn mailing list