What the heck is wrong with CTFE's?

John Colvin john.loughran.colvin at gmail.com
Mon Jul 8 16:36:44 PDT 2013


On Monday, 8 July 2013 at 22:57:17 UTC, JS wrote:
> 	int i = 0;
> 	foreach(t; T)
> 	{
> 		string name = "Value"~((i==0) ? "" : (to!string(i)));
> 		i++;
> 	}

That increments i, both ctfe and rt.
>
>
> vs
>
> 	int i = 0;
> 	foreach(t; T)
> 	{
> 		string name = "Value"~((i==0) ? "" : (to!string(i++)));		
> 	}

This will never increment i, whether in ctfe or at runtime. The 
entire "(to!string(i++))"  will never be executed.

> vs
>
>
> 	foreach(i, t; T)
> 	{
> 		string name = "Value"~((i==0) ? "" : (to!string(i)));
> 	}

This will increment i, both in ctfe and at runtime.


More information about the Digitalmars-d mailing list