Skip to content

Commit

Permalink
Merge pull request #545 from eco/iota-pop-empty
Browse files Browse the repository at this point in the history
fix Issue 7944 - std.range.iota.popFront() cycles when the range is empty
  • Loading branch information
dsimcha committed Apr 23, 2012
2 parents b1252f3 + 23bfcd7 commit 9233d3d
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions std/range.d
Expand Up @@ -4353,15 +4353,17 @@ if ((isIntegral!(CommonType!(B, E)) || isPointer!(CommonType!(B, E)))
}
}
@property bool empty() const { return current == pastLast; }
@property Value front() { return current; }
@property Value front() { assert(!empty); return current; }
alias front moveFront;
void popFront() { current += step; }
@property Value back() { return pastLast - step; }
void popFront() { assert(!empty); current += step; }
@property Value back() { assert(!empty); return pastLast - step; }
alias back moveBack;
void popBack() { pastLast -= step; }
void popBack() { assert(!empty); pastLast -= step; }
@property auto save() { return this; }
Value opIndex(ulong n)
{
assert(n < this.length);

// Just cast to Value here because doing so gives overflow behavior
// consistent with calling popFront() n times.
return cast(Value) (current + step * n);
Expand Down Expand Up @@ -4419,15 +4421,17 @@ if (isIntegral!(CommonType!(B, E)) || isPointer!(CommonType!(B, E)))
}
}
@property bool empty() const { return current == pastLast; }
@property Value front() { return current; }
@property Value front() { assert(!empty); return current; }
alias front moveFront;
void popFront() { ++current; }
@property Value back() { return pastLast - 1; }
void popFront() { assert(!empty); ++current; }
@property Value back() { assert(!empty); return pastLast - 1; }
alias back moveBack;
void popBack() { --pastLast; }
void popBack() { assert(!empty); --pastLast; }
@property auto save() { return this; }
Value opIndex(ulong n)
{
assert(n < this.length);

// Just cast to Value here because doing so gives overflow behavior
// consistent with calling popFront() n times.
return cast(Value) (current + n);
Expand Down Expand Up @@ -4490,7 +4494,7 @@ if (isFloatingPoint!(CommonType!(B, E, S)))
}
}
@property bool empty() const { return index == count; }
@property Value front() { return start + step * index; }
@property Value front() { assert(!empty); return start + step * index; }
alias front moveFront;
void popFront()
{
Expand Down

0 comments on commit 9233d3d

Please sign in to comment.