diff --git a/std/algorithm.d b/std/algorithm.d index 6208c640a..43b2015e4 100644 --- a/std/algorithm.d +++ b/std/algorithm.d @@ -871,6 +871,19 @@ unittest auto d = c[0 .. 1]; } +unittest +{ + static struct Range + { + bool initialized = false; + bool front() @property {return initialized = true;} + void popFront() {initialized = false;} + enum empty = false; + } + auto r = Range().cache(); + assert(r.source.initialized == true); +} + private struct Cache(R, bool bidir) { import core.exception : RangeError; @@ -895,9 +908,9 @@ private struct Cache(R, bool bidir) source = range; if (!range.empty) { - caches[0] = range.front; + caches[0] = source.front; static if (bidir) - caches[1] = range.back; + caches[1] = source.back; } }