Alias this with array can only be used once
Blake Anderton
rbanderton at gmail.com
Wed Feb 22 14:16:41 PST 2012
Why doesn't this work? I'm assuming I'm not fully understanding
how "alias this" interacts with ranges (i.e. the range isn't
being reset after count is finished with it), but I'm not sure
how to fix this either:
import std.algorithm;
class ArrayContainer
{
int[] values;
this(int[] v) { values = v; }
alias values this;
}
void main(string[] args)
{
auto c = new ArrayContainer([1, 2, 3]);
assert(count(c) == 3); //succeeds
assert(c.length == 3); //FAILS - is actually zero
}
More information about the Digitalmars-d-learn
mailing list