Thread overview
[Issue 13971] Writing a container should write its default range
Jan 12, 2015
Adam D. Ruppe
Jan 13, 2015
Daniel Kozak
Jan 17, 2015
Petar Kirov
Jan 17, 2015
Petar Kirov
Feb 13, 2021
Walter Bright
Mar 24, 2021
Berni44
Dec 17, 2022
Iain Buclaw
January 12, 2015
https://issues.dlang.org/show_bug.cgi?id=13971

Adam D. Ruppe <destructionator@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |destructionator@gmail.com

--- Comment #1 from Adam D. Ruppe <destructionator@gmail.com> ---
I'm not sure this should be in writeln btw, I think Array and friends should just have a toString(sink) function that forwards to the range.

We could provide a phobos mixin template forwardToStringTo!(member) to keep it
DRY.

--
January 13, 2015
https://issues.dlang.org/show_bug.cgi?id=13971

Daniel Kozak <kozzi11@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kozzi11@gmail.com

--- Comment #2 from Daniel Kozak <kozzi11@gmail.com> ---
It could be done easily by add few lines of code to std.format.formatValue.

Adding something like this:

else static if (__traits(compiles, val[]) && isInputRange!(typeof(val[])))
    {
        auto refVal = val[];
        formatRange(w, refVal, f);
}

to

void formatValue(Writer, T, Char)(Writer w, auto ref T val, ref FormatSpec!Char
f)
if ((is(T == struct) || is(T == union)) && (hasToString!(T, Char) ||
!is(BuiltinTypeOf!T)) && !is(T == enum))

--
January 17, 2015
https://issues.dlang.org/show_bug.cgi?id=13971

Petar Kirov <petar.p.kirov@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |petar.p.kirov@gmail.com

--- Comment #3 from Petar Kirov <petar.p.kirov@gmail.com> ---
IMO, this is a nice feature, but it's not a big deal that it doesn't work currently. For example the following in C#:

var l = new List<int> { 2, 6, 8, 4, 1 };
Console.WriteLine(l);

Prints:
System.Collections.Generic.List`1[System.Int32]

I think that %s should print something like Array!int@20D9590, thus hiding the implementation details and only revealing the identity (the address) of the container. The %s should print contents only if you provide a range (built-in arrays and AAs are more of a range, IMO).

Perhaps we should introduce a new format spec for printing the contents of containers, like %r (or a more appropriate letter). E.g.:

import std.container, std.range, std.algorithm, std.stdio;
void main()
{
  Array!int arr;
  iota(100).each!(i => arr.insertBack(i));
  writefln("%5r", arr);
}

Should print:
[0, 1, 2, 3, 4]

Where the '5' in %5r is the FormatSpec width and means print the first 5 elements.

--
January 17, 2015
https://issues.dlang.org/show_bug.cgi?id=13971

Petar Kirov <petar.p.kirov@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Hardware|x86                         |All
                 OS|Mac OS X                    |All

--
February 13, 2021
https://issues.dlang.org/show_bug.cgi?id=13971

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=3248

--
March 24, 2021
https://issues.dlang.org/show_bug.cgi?id=13971

Berni44 <bugzilla@bernis-buecher.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@bernis-buecher.de

--- Comment #4 from Berni44 <bugzilla@bernis-buecher.de> ---
Meanwhile (with DMD64 D Compiler v2.096.0-rc.1-22-g6d8985b48) the output of
Andreis snippet is

Array!int(Payload(1, [10]))

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=13971

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P4

--
December 01
https://issues.dlang.org/show_bug.cgi?id=13971

--- Comment #5 from dlangBugzillaToGithub <robert.schadek@posteo.de> ---
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/phobos/issues/10110

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB

--