Output ranges and arrays

Lars T. Kyllingstad public at kyllingen.NOSPAMnet
Fri Nov 12 06:40:41 PST 2010


On Fri, 12 Nov 2010 15:22:20 +0100, Olivier Pisano wrote:

> Hi,
> 
> I am starting to play with output ranges and have trouble understanding
> how they do work on arrays. Consider the following code :
> 
> 	import std.array;
> 	import std.range;
> 	import std.stdio;
> 
> 	void main(string[] argv)
> 	{
> 	    auto a = [1, 2, 3];
> 	    a.put(4);
> 
> 	    writefln("%s", a);
> 	}
> 
> One could expect the call to put() to append 4 to the array so the array
> content would be [1, 2, 3, 4].
> Instead of this, I get "[2, 3]" to be printed. So I guess put() is
> translated to
> 
> 	r.front = e; r.popFront();
> 
> as written in std.range.put documentation.
> 
> Is it the expected behaviour or is it a bug ?


Here's a discussion from earlier this year:

http://www.digitalmars.com/d/archives/digitalmars/D/
std.array.put_doesn_t_put_106871.html

-Lars


More information about the Digitalmars-d mailing list