Fix for moveFront, moveBack, and moveAt

- I assume they are not properties, then changed to normal functions.
- Global .moveFront/Back uses front and back if member moveFront/back doesn't exist.
  Then, member aliases are just redundant.
This commit is contained in:
k-hara 2012-11-23 00:30:49 +09:00
parent 128aa9f8fc
commit 58a8ccf42e
2 changed files with 19 additions and 11 deletions

View file

@ -6479,7 +6479,6 @@ unittest
bool empty() { return i >= data.length; }
T front() { return data[i]; }
T front(real e) { return data[i] = cast(T) e; }
alias front moveFront;
}
void popFront() { ++i; }
}

View file

@ -4048,7 +4048,7 @@ if(Ranges.length && allSatisfy!(isInputRange, staticMap!(Unqual, Ranges)))
*/
static if (allSatisfy!(hasMobileElements, R))
{
@property ElementType moveBack()
ElementType moveBack()
{
ElementType result = void;
foreach (i, Unused; R)
@ -4943,14 +4943,16 @@ if ((isIntegral!(CommonType!(B, E)) || isPointer!(CommonType!(B, E)))
this.step = 1;
}
}
@property bool empty() const { return current == pastLast; }
@property inout(Value) front() inout { assert(!empty); return current; }
alias front moveFront;
void popFront() { assert(!empty); current += step; }
@property inout(Value) back() inout { assert(!empty); return pastLast - step; }
alias back moveBack;
void popBack() { assert(!empty); pastLast -= step; }
@property auto save() { return this; }
inout(Value) opIndex(ulong n) inout
{
assert(n < this.length);
@ -5017,14 +5019,16 @@ if (isIntegral!(CommonType!(B, E)) || isPointer!(CommonType!(B, E)))
this.current = this.pastLast = current;
}
}
@property bool empty() const { return current == pastLast; }
@property inout(Value) front() inout { assert(!empty); return current; }
alias front moveFront;
void popFront() { assert(!empty); ++current; }
@property inout(Value) back() inout { assert(!empty); return pastLast - 1; }
alias back moveBack;
void popBack() { assert(!empty); --pastLast; }
@property auto save() { return this; }
inout(Value) opIndex(ulong n) inout
{
assert(n < this.length);
@ -5068,6 +5072,7 @@ if (isFloatingPoint!(CommonType!(B, E, S)))
{
private Value start, step;
private size_t index, count;
this(Value start, Value end, Value step)
{
this.start = start;
@ -5088,9 +5093,9 @@ if (isFloatingPoint!(CommonType!(B, E, S)))
assert(start + count * step <= end);
}
}
@property bool empty() const { return index == count; }
@property Value front() const { assert(!empty); return start + step * index; }
alias front moveFront;
void popFront()
{
assert(!empty);
@ -5101,13 +5106,14 @@ if (isFloatingPoint!(CommonType!(B, E, S)))
assert(!empty);
return start + step * (count - 1);
}
alias back moveBack;
void popBack()
{
assert(!empty);
--count;
}
@property auto save() { return this; }
Value opIndex(size_t n) const
{
assert(n < count);
@ -7918,7 +7924,8 @@ assert(buffer2 == [11, 12, 13, 14, 15]);
Only defined if $(D hasMobileElements!R) and $(D isForwardRange!R) are
$(D true).
+/
static if(hasMobileElements!R && isForwardRange!R) @property auto moveFront()
static if(hasMobileElements!R && isForwardRange!R)
auto moveFront()
{
return (*_range).moveFront();
}
@ -7928,7 +7935,8 @@ assert(buffer2 == [11, 12, 13, 14, 15]);
Only defined if $(D hasMobileElements!R) and $(D isBidirectionalRange!R)
are $(D true).
+/
static if(hasMobileElements!R && isBidirectionalRange!R) @property auto moveBack()
static if(hasMobileElements!R && isBidirectionalRange!R)
auto moveBack()
{
return (*_range).moveBack();
}
@ -7938,7 +7946,8 @@ assert(buffer2 == [11, 12, 13, 14, 15]);
Only defined if $(D hasMobileElements!R) and $(D isRandomAccessRange!R)
are $(D true).
+/
static if(hasMobileElements!R && isRandomAccessRange!R) @property auto moveAt(IndexType)(IndexType index)
static if(hasMobileElements!R && isRandomAccessRange!R)
auto moveAt(IndexType)(IndexType index)
if(is(typeof((*_range).moveAt(index))))
{
return (*_range).moveAt(index);