On 24/12/13 12:57, Jakob Ovrum wrote:
Implement `back` is really trivial.
Simplified example:
---
auto iota(T)(T start, T end)
{
static struct Result
{
T start, end;
bool empty() @property { return start == end; }
T front() @property { return start; }
void popFront() { ++start; }
T back() @property { return end; }
void popBack() { --end; }
// etc
}
return Result(start, --end);
}
Complication: as it stands, iota is defined as an open interval; its values
consist of
start, start + delta, start + 2*delta, ..., start + n*delta
... where n is the largest possible value of n such that start + n*delta < end.
It's NOT however guaranteed that start + n*delta == end - delta. Consider:
iota(0.0, 0.91, 0.1) // gives 0.0, 0.1, ..., 0.8, 0.9
So, absent the ability to calculate start + n*delta in O(1), it's _not_ trivial
to calculate the initial value of .back.