The following program:
import std.utf;
import core.stdc.stdio;
struct S {
bool empty() { printf("empty\n"); return !s.length; }
@property char front() { printf("front\n"); return s[0]; }
void popFront() { printf("popFront()\n"); s = s[1 .. $]; }
string s;
}
void main() {
auto s = S("hello");
auto r = s.byDchar();
r.empty;
r.front;
r.popFront();
r.empty;
r.front;
r.popFront();
}
prints 'empty' twice:
empty
empty
front
popFront()
empty
empty
front
popFront()
For efficiency, it should only call empty once per character.
Comment #1 by john.loughran.colvin — 2015-10-07T12:59:24Z