Bug 10904 – "%(%s %)" format string support for std.container.Array too
Status
RESOLVED
Resolution
INVALID
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-08-26T14:02:00Z
Last change time
2014-06-15T20:43:18Z
Assigned to
nobody
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2013-08-26T14:02:29Z
import std.stdio: writefln;
import std.container: Array;
void main() {
int[10] a1;
writefln("%(%d %)", a1);
Array!int a2;
a2.length = 10;
writefln("%(%d %)", a2);
}
With dmd 2.064alpha it gives a run-time error:
std.format.FormatException@...\dmd2\src\phobos\std\format.d(2472): Expected '%s' format specifier for type 'Array!int'
Comment #1 by hsteoh — 2013-08-26T22:09:28Z
Hmm. Looking at the code, it seems that %(...%) _should_ be able to support any input range, so if you write writefln("%(...%)", a1[]);, it should work, I think.
Comment #2 by hsteoh — 2013-08-26T22:11:26Z
OK, confirmed that using opSlice (i.e., a2[]) works.
It's not as nice, though. We *could* implement a suitable version of toString that will get picked up by std.format without needing to write [].
Comment #3 by dmitry.olsh — 2013-08-27T05:19:47Z
(In reply to comment #2)
> OK, confirmed that using opSlice (i.e., a2[]) works.
>
> It's not as nice, though. We *could* implement a suitable version of toString
> that will get picked up by std.format without needing to write [].
Well, that would going way too long in the wrong direction. %(..%) prints ranges, period. Leave containers alone :)
Comment #4 by bearophile_hugs — 2013-08-27T05:56:43Z
(In reply to comment #3)
> Well, that would going way too long in the wrong direction. %(..%) prints
> ranges, period. Leave containers alone :)
OK, I close down this ER. Thank you for all the answers.
Comment #5 by github-bugzilla — 2014-06-15T20:43:18Z