Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

fix Issue 7944 - std.range.iota.popFront() cycles when the range is empty #545

Merged
merged 2 commits into from

3 participants

Brad Anderson Steven Schveighoffer David Simcha
Brad Anderson

Added !empty assertions to front, popFront, back, and popBack to the integer iota like some other ranges do to catch popping an empty range. Also added the !empty assert to floating point iota front() which was the only one of those four that was missing.

http://d.puremagic.com/issues/show_bug.cgi?id=7944

Brad Anderson eco fix Issue 7944 - std.range.iota.popFront() cycles when the range is e…
…mpty

Added !empty assertions to front, popFront, back, and popBack to the integer
iota like some other ranges do. Also added the one that was missing to the
floating point iota.
028699f
Steven Schveighoffer
Collaborator

Should we add asserts in opIndex?

Brad Anderson

Makes sense. I'll take a look.

David Simcha dsimcha merged commit 9233d3d into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 20, 2012
  1. Brad Anderson

    fix Issue 7944 - std.range.iota.popFront() cycles when the range is e…

    eco authored
    …mpty
    
    Added !empty assertions to front, popFront, back, and popBack to the integer
    iota like some other ranges do. Also added the one that was missing to the
    floating point iota.
Commits on Apr 21, 2012
  1. Brad Anderson
This page is out of date. Refresh to see the latest.
Showing with 13 additions and 9 deletions.
  1. +13 −9 std/range.d
22 std/range.d
View
@@ -4352,15 +4352,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);
@@ -4418,15 +4420,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);
@@ -4489,7 +4493,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()
{
Something went wrong with that request. Please try again.