Ranges: is it ok if front is a data member?

qznc qznc at web.de
Thu Dec 12 23:28:55 PST 2013


On Thursday, 12 December 2013 at 21:55:20 UTC, Ali Çehreli wrote:
> The third condition that is checked to determine whether it is 
> an OutputRange is indeed assignment to front.
>
>   http://dlang.org/phobos/std_range.html#.put
>
> That condition is what makes a slice an OutputRange, which 
> causes the super confusing state of "output range losing 
> elements after put'ting": :)
>
> import std.range;
>
> void main()
> {
>     auto s = [ 1, 2, 3 ];
>     s.put(10);
>     assert(s.length == 2); // PASSES! :p
> }

Ouch. That surely is confusing. Why don't arrays provide .put 
which appends the element?


More information about the Digitalmars-d-learn mailing list