Comment #0 by bearophile_hugs — 2010-08-21T10:31:18Z
This correct D2 program:
import std.stdio: writeln;
void main() {
int[int] aa = [1:2, 3:4, 5:6];
auto vals = aa.byValue();
foreach (v; vals)
writeln(v);
}
Outputs with dmd 2.048:
2
4
6
-------------------
But this other program:
import std.stdio: writeln;
void main() {
int[int] aa = [1:2, 3:4, 5:6];
auto vals = aa.byValue();
writeln(vals);
}
writeln() seems unable to print them:
...\dmd\src\phobos\std\format.d(1364): Error: template std.format.formatValue(Writer,T,Char) if (is(const(T) == const(void[]))) does not match any function template declaration
...\dmd\src\phobos\std\format.d(1364): Error: template std.format.formatValue(Writer,T,Char) if (is(const(T) == const(void[]))) cannot deduce template function from argument types !()(LockingTextWriter,int delegate(int delegate(ref int) dg),FormatSpec!(immutable(char)))
...\dmd\src\phobos\std\format.d(305): Error: template instance std.format.formatGeneric!(LockingTextWriter,int delegate(int delegate(ref int) dg),immutable(char)) error instantiating
...\dmd\src\phobos\std\stdio.d(595): instantiated from here: formattedWrite!(LockingTextWriter,immutable(char),int delegate(int delegate(ref int) dg))
...\dmd\src\phobos\std\stdio.d(1372): instantiated from here: write!(int delegate(int delegate(ref int) dg),char)
test.d(6): instantiated from here: writeln!(int delegate(int delegate(ref int) dg))
-------------------
And the array() of dmd 2.048 seems unable to create an array (maybe this is already fixed in SVN):
import std.array: array;
void main() {
int[int] aa = [1:2, 3:4, 5:6];
auto vals = aa.byValue();
int[] avals = array(vals);
}
test.d(5): Error: template std.array.array(Range) if (isInputRange!(Range)) does not match any function template declaration
test.d(5): Error: template std.array.array(Range) if (isInputRange!(Range)) cannot deduce template function from argument types !()(int delegate(int delegate(ref int) dg))
Similar problems are present with .byKey().
Comment #1 by kennytm — 2011-04-11T14:12:10Z
The 2nd program now (2.052) prints
int delegate(int delegate(ref int))
while the 3rd program now works correctly.
Comment #2 by kennytm — 2011-05-08T00:07:33Z
*** Issue 5951 has been marked as a duplicate of this issue. ***
Comment #3 by bearophile_hugs — 2012-01-17T14:09:39Z