D Language Gotchas

safety0ff safety0ff.dev at gmail.com
Tue Nov 5 09:14:22 PST 2013


One other gotcha that I've run into is trying to use foreach on a 
range of tuples with an iteration index. It does not do what you 
might expect, try:
import std.range, std.stdio;
void main()
{
	auto a = repeat(1,5);
	auto b = repeat(2,5);
	foreach(i, ab; a.zip(b)) writeln(i, " ", ab);
}

See bugzilla #5550 for bearophile's range.enumerate enhancement 
request.


More information about the Digitalmars-d mailing list