Map one tuple to another Tuple of different type

via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jul 22 11:07:35 PDT 2014


On Tuesday, 22 July 2014 at 16:42:14 UTC, H. S. Teoh via 
Digitalmars-d-learn wrote:
> On Tue, Jul 22, 2014 at 03:52:14PM +0000, Vlad Levenfeld via 
> Digitalmars-d-learn wrote:
>> Anyway my actual question is: if all values are constant at 
>> compile
>> time, how would a static while loop terminate?
>
> Basically, think of it as custom loop unrolling:
>
> 	TypeTuple!(
> 		int, "x",
> 		float, "y",
> 		uint, "z"
> 	) t;
>
> 	// This loop:
> 	foreach (i; staticIota(0, 3)) {
> 		t[i]++;
> 	}
>
> 	// Is equivalent to:
> 	t[0]++;
> 	t[1]++;
> 	t[2]++;
>
> 	// Which is equivalent to:
> 	t.x++;
> 	t.y++;
> 	t.z++;
>
> The loop body is basically expanded for each iteration, with 
> the loop
> variable suitably substituted with each element of the typelist.

You're misunderstanding him. Your example is a static foreach, 
but Vlad asked about static while. I too don't see how a static 
while is supposed to work.


More information about the Digitalmars-d-learn mailing list