Built-in arrays as output ranges
Steve Teale
steve.teale at britseyeview.com
Sun Feb 7 00:13:45 PST 2010
Not a bug, but would it be reasonable to expand a little on the documentation for an output range, perhaps along the lines:
r.put(e) puts e in the range (in a range-dependent manner) and advances to the popFront position in the range. Successive calls to r.put add elements to the range. put may throw to signal failure.
When using a built-in array as an output range, to do anything useful it is necessary to take a reference to the original array before using put. The original array will be nibbled away by put operations (see std.array). For example:
int[] a = [ 1,2,3 ];
int[] b = a;
a.put(-a[0]);
a.put(-a[0]);
writefln("([%s] [%s]", b, a);
// [ -1, -2, 3] [ 3 ]
More information about the Digitalmars-d
mailing list