mirror of
https://github.com/dlang/phobos.git
synced 2025-04-30 15:10:46 +03:00
Tweak cache constructor
This commit is contained in:
parent
4ae1b147a3
commit
282fc0189e
1 changed files with 15 additions and 2 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue