@property and infiniteness propagation in std.algorithm.

This commit is contained in:
David Simcha 2010-07-01 02:39:50 +00:00
parent 96aed784bc
commit 18e300d60f

View file

@ -577,7 +577,7 @@ struct Filter(alias pred, Range) if (isInputRange!(Range))
} }
static if(isInfinite!Range) { static if(isInfinite!Range) {
enum bool empty = false; enum bool empty = false; // Propagate infiniteness.
} else { } else {
bool empty() { return _input.empty; } bool empty() { return _input.empty; }
} }
@ -874,9 +874,15 @@ public:
// computeBack(); // computeBack();
} }
@property bool empty() static if(isInfinite!Range)
{ {
return _frontLength == _atEnd; enum bool empty = false;
} else
{
@property bool empty()
{
return _frontLength == _atEnd;
}
} }
@property Range front() @property Range front()
@ -996,16 +1002,23 @@ public:
_separator = separator; _separator = separator;
} }
Range front() @property Range front()
{ {
assert(!empty); assert(!empty);
ensureFrontLength; ensureFrontLength;
return _input[0 .. _frontLength]; return _input[0 .. _frontLength];
} }
bool empty() static if(isInfinite!Range)
{ {
return _frontLength == size_t.max && _input.empty; enum bool empty = false; // Propagate infiniteness
}
else
{
@property bool empty()
{
return _frontLength == size_t.max && _input.empty;
}
} }
void popFront() void popFront()
@ -1041,7 +1054,7 @@ public:
// Bidirectional functionality as suggested by Brad Roberts. // Bidirectional functionality as suggested by Brad Roberts.
static if (isBidirectionalRange!Range) static if (isBidirectionalRange!Range)
{ {
Range back() @property Range back()
{ {
ensureBackLength; ensureBackLength;
return _input[_input.length - _backLength .. _input.length]; return _input[_input.length - _backLength .. _input.length];
@ -1143,9 +1156,16 @@ struct Splitter(alias isTerminator, Range,
} }
} }
@property bool empty() static if(isInfinite!Range)
{ {
return _end == _end.max; enum bool empty = false; // Propagate infiniteness.
}
else
{
@property bool empty()
{
return _end == _end.max;
}
} }
@property Range front() @property Range front()
@ -1257,7 +1277,10 @@ struct Uniq(alias pred, R)
while (!_input.empty && binaryFun!(pred)(last, _input.front)); while (!_input.empty && binaryFun!(pred)(last, _input.front));
} }
static if(isBidirectionalRange!R) { @property ElementType!(R) front() { return _input.front; }
static if(isBidirectionalRange!R)
{
void popBack() void popBack()
{ {
auto last = _input.back; auto last = _input.back;
@ -1268,11 +1291,18 @@ struct Uniq(alias pred, R)
while (!_input.empty && binaryFun!(pred)(last, _input.back)); while (!_input.empty && binaryFun!(pred)(last, _input.back));
} }
ElementType!(R) back() { return _input.back; } @property ElementType!(R) back() { return _input.back; }
}
static if(isInfinite!R)
{
enum bool empty = false; // Propagate infiniteness.
}
else
{
@property bool empty() { return _input.empty; }
} }
bool empty() { return _input.empty; }
ElementType!(R) front() { return _input.front; }
static if(isForwardRange!R) { static if(isForwardRange!R) {
@property typeof(this) save() { @property typeof(this) save() {
@ -1355,9 +1385,16 @@ struct Group(alias pred, R) if (isInputRange!R)
} }
} }
@property bool empty() static if(isInfinite!R)
{ {
return _current.field[1] == 0; enum bool empty = false; // Propagate infiniteness.
}
else
{
@property bool empty()
{
return _current.field[1] == 0;
}
} }
@property ref Tuple!(ElementType!R, uint) front() @property ref Tuple!(ElementType!R, uint) front()
@ -2038,12 +2075,12 @@ struct Until(alias pred, Range, Sentinel) if (isInputRange!Range)
_done = _input.empty || openRight && predSatisfied(); _done = _input.empty || openRight && predSatisfied();
} }
bool empty() @property bool empty()
{ {
return _done; return _done;
} }
ElementType!Range front() @property ElementType!Range front()
{ {
assert(!empty); assert(!empty);
return _input.front; return _input.front;
@ -5474,7 +5511,7 @@ public:
adjustPosition(); adjustPosition();
} }
bool empty() @property bool empty()
{ {
return _crt == _crt.max; return _crt == _crt.max;
} }
@ -5495,7 +5532,7 @@ public:
assert(false); assert(false);
} }
ElementType front() @property ElementType front()
{ {
assert(!empty); assert(!empty);
// Assume _crt is correct // Assume _crt is correct
@ -5593,7 +5630,7 @@ public:
adjustPosition; adjustPosition;
} }
bool empty() @property bool empty()
{ {
foreach (i, U; Rs) foreach (i, U; Rs)
{ {
@ -5612,7 +5649,7 @@ public:
adjustPosition; adjustPosition;
} }
ElementType front() @property ElementType front()
{ {
assert(!empty); assert(!empty);
return _input[0].front; return _input[0].front;
@ -5697,7 +5734,7 @@ public:
adjustPosition; adjustPosition;
} }
ElementType!(R1) front() @property ElementType!(R1) front()
{ {
assert(!empty); assert(!empty);
return r1.front; return r1.front;
@ -5788,7 +5825,7 @@ public:
adjustPosition; adjustPosition;
} }
ElementType!(R1) front() @property ElementType!(R1) front()
{ {
assert(!empty); assert(!empty);
if (r2.empty || !r1.empty && comp(r1.front, r2.front)) if (r2.empty || !r1.empty && comp(r1.front, r2.front))
@ -5801,7 +5838,7 @@ public:
ref auto opSlice() { return this; } ref auto opSlice() { return this; }
bool empty() { return r1.empty && r2.empty; } @property bool empty() { return r1.empty && r2.empty; }
} }
/// Ditto /// Ditto
@ -5938,9 +5975,9 @@ struct NWayUnion(alias less, RangeOfRanges)
_heap.acquire(_ror); _heap.acquire(_ror);
} }
bool empty() { return _ror.empty; } @property bool empty() { return _ror.empty; }
ref ElementType front() @property ref ElementType front()
{ {
return _heap.front.front; return _heap.front.front;
} }