Expected or Bug? struct range unmodified after foreach
Jesse Phillips
jessekphillips+d at gmail.com
Sun Nov 6 15:26:02 PST 2011
I'm sure if this was changed there would be other interesting behavior,
such as arrays being consumed. And suggestions other than
for(S s; !s.empty, s.popFront())...
Example:
void main() {
S s;
foreach(i; s) {
assert(i == s.popCount); // Fail
}
assert(s.popCount == 10); // Fail
}
struct S {
size_t popCount;
auto empty() {
if(popCount > 9)
return true;
return false;
}
auto front() { return popCount; }
auto popFront() {
popCount++;
}
}
More information about the Digitalmars-d-learn
mailing list