mirror of
https://github.com/dlang/phobos.git
synced 2025-05-01 23:50:31 +03:00
Merge pull request #2582 from monarchdodra/cacheBug
Tweak cache constructor
This commit is contained in:
commit
95222b884d
1 changed files with 15 additions and 2 deletions
|
@ -877,6 +877,19 @@ unittest
|
||||||
auto d = c[0 .. 1];
|
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)
|
private struct Cache(R, bool bidir)
|
||||||
{
|
{
|
||||||
import core.exception : RangeError;
|
import core.exception : RangeError;
|
||||||
|
@ -901,9 +914,9 @@ private struct Cache(R, bool bidir)
|
||||||
source = range;
|
source = range;
|
||||||
if (!range.empty)
|
if (!range.empty)
|
||||||
{
|
{
|
||||||
caches[0] = range.front;
|
caches[0] = source.front;
|
||||||
static if (bidir)
|
static if (bidir)
|
||||||
caches[1] = range.back;
|
caches[1] = source.back;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue