Printing an std.container.Array

Bayan Rafeh via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Apr 17 06:59:36 PDT 2015


On Thursday, 16 April 2015 at 20:08:30 UTC, H. S. Teoh 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


Thanks that works great, though I still don't understand where 
the controversy is coming from. There was a mention of causing 
confusion between containers and ranges. How so?


More information about the Digitalmars-d-learn mailing list