On Tuesday, 24 December 2013 at 11:47:12 UTC, Francesco Cattoglio
wrote:
Correct, but there's no way to compute "back" with less than
O(n) complexity, unless division by increment is available.
(Actually, I think we can achieve O(log n) with multiplication
alone, but I think it might be lots of work with very little
benefits)
I should have specified better: we need to provide `back', and
Andrei suggested that no primitive should be more than complex
than O(1).
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);
}
---