On Thursday, 10 December 2015 at 00:36:27 UTC, Jon D wrote:
Question I have is if there is a better way to do this. For
example, a different way to construct the lazy
'decodeUTF8Range' rather than writing it out in this fashion.
A further thought - The decodeUTF8Range function is basically
constructing a lazy wrapper range around decodeFront, which is
effectively combining a 'front' and 'popFront' operation. So
perhaps a generic way to compose a wrapper for such functions.
auto decodeUTF8Range(Range)(Range charSource)
if (isInputRange!Range && is(Unqual!(ElementType!Range) ==
char))
{
static struct Result
{
private Range source;
private dchar next;
bool empty = false;
dchar front() @property { return next; }
void popFront() {
if (source.empty) {
empty = true;
next = dchar.init;
} else {
next = source.decodeFront;
}
}
}
auto r = Result(charSource);
r.popFront;
return r;
}