Printing an std.container.Array
Daniel Kozak via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Apr 16 13:14:18 PDT 2015
On Thu, 16 Apr 2015 13:05:48 -0700
"H. S. Teoh via Digitalmars-d-learn" <digitalmars-d-learn at puremagic.com> wrote:
> On Thu, Apr 16, 2015 at 07:55:52PM +0000, Bayan Rafeh via Digitalmars-d-learn
> wrote:
> > Executing this code:
> >
> > import std.container.array;
> > import std.stdio;
> >
> >
> > int main() {
> > writeln(Array!int([1, 2]));
> > return 0;
> > }
> >
> > outputs the following:
> >
> > Array!int(RefCounted!(Payload,
> > cast(RefCountedAutoInitialize)0)(RefCountedStore(B694B0)))
> >
> >
> > The strange thing is that this works fine:
> >
> > import std.container.array;
> > import std.stdio;
> >
> > int main() {
> > writeln(Array!int([1, 2])[0..$]);
> > return 0;
> > }
> >
> > [1, 2]
> >
> > How am I supposed to interpret this?
>
> Try slicing the Array before passing it to writeln?
>
> writeln(Array!int([1, 2])[]);
>
> Basically, there is a distinction between a container and a range that
> spans the items in a container. The conventional syntax for getting a
> range over a container's contents is the slicing operator [].
>
>
> T
>
Yep, but problem is almost no one expect this, or know this. We definitely
should do better.
More information about the Digitalmars-d-learn
mailing list