Bug 12435 – std.range.transposed for immutable matrix too

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2014-03-21T14:30:28Z
Last change time
2019-12-19T11:06:08Z
Keywords
rejects-valid
Assigned to
No Owner
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2014-03-21T14:30:28Z
void main() { import std.stdio: writeln; import std.range: transposed; immutable m = [[10, 20], [30, 40]]; auto t = m.transposed; t.writeln; } dmd 2.066alpha gives: ...\dmd2\src\phobos\std\range.d(6705,23): Error: template std.array.popFront cannot deduce function from argument types !()(immutable(int[])), candidates are: ...\dmd2\src\phobos\std\array.d(569,6): std.array.popFront(T)(ref T[] a) if (!isNarrowString!(T[]) && !is(T[] == void[])) ...\dmd2\src\phobos\std\array.d(592,6): std.array.popFront(C)(ref C[] str) if (isNarrowString!(C[])) ...\dmd2\src\phobos\std\format.d(2556,17): Error: template instance std.range.isInputRange!(Transposed!(immutable(int[])[])) error instantiating ...\dmd2\src\phobos\std\format.d(2781,5): instantiated from here: enforceValidFormatSpec!(Transposed!(immutable(int[])[]), char) ...\dmd2\src\phobos\std\format.d(3082,16): instantiated from here: formatValue!(LockingTextWriter, Transposed!(immutable(int[])[]), char) ...\dmd2\src\phobos\std\format.d(423,54): instantiated from here: formatGeneric!(LockingTextWriter, Transposed!(immutable(int[])[]), char) ...\dmd2\src\phobos\std\stdio.d(1158,42): ... (1 instantiations, -v to show) ... ...\dmd2\src\phobos\std\stdio.d(2535,21): instantiated from here: write!(Transposed!(immutable(int[])[]), char) test.d(6,6): instantiated from here: writeln!(Transposed!(immutable(int[])[])) ...\dmd2\src\phobos\std\format.d(3105,9): Warning: switch case fallthrough - use 'goto default;' if intended ...\dmd2\src\phobos\std\format.d(3105,9): Warning: switch case fallthrough - use 'goto default;' if intended While this simpler program: void main() { import std.range: transposed; immutable m = [[10, 20], [30, 40]]; auto t = m.transposed; foreach (row; t) {} } Gives: ...\dmd2\src\phobos\std\range.d(6705,23): Error: template std.array.popFront cannot deduce function from argument types !()(immutable(int[])), candidates are: ...\dmd2\src\phobos\std\array.d(569,6): std.array.popFront(T)(ref T[] a) if (!isNarrowString!(T[]) && !is(T[] == void[])) ...\dmd2\src\phobos\std\array.d(592,6): std.array.popFront(C)(ref C[] str) if (isNarrowString!(C[]))
Comment #1 by bugzilla — 2019-12-19T11:06:08Z
Ranges cannot be immutables and therefore transposed cannot be called on m.