Formatted output of range of tuples

antropod via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Oct 8 14:21:45 PDT 2014


Hello!

Consider this code:

+++
import std.stdio;
import std.range;
import std.algorithm;

void printIndexedArray1(T, Range)(T[] source, Range indexes)
{
	foreach(row; zip(indexes, source))
	{
		foreach(col; row) {
			write(col, " ");
		}
		writeln;
	}
}

void printIndexedArray2(T, Range)(T[] source, Range indexes)
{
	writef("%(%(%s %)\n%)", zip(indexes, source));
}

void main()
{
	uint[] data = [17, 30, 48, 140, 10, 01, 126, 138, 140, 3, 501];
	printIndexedArray1(data, sequence!"n");
	printIndexedArray2(data, sequence!"n");

}
+++

Looks fairly straightforward. But, the second function causes 
compilation error:

std.format.FormatException at C:\D\dmd2\windows\bin\..\..\src\phobos\std\format.d(2
585): Expected '%s' format specifier for type 'Tuple!(uint, uint)'

Can you help me with that?


More information about the Digitalmars-d-learn mailing list