mirror of
https://github.com/dlang/phobos.git
synced 2025-05-10 14:08:32 +03:00
fix Issue 8240 - std.algorithm.joiner and empty inputRangeObject
In this case, _current member is invalid at the start of iteration. Then joiner should have additional member _valid_current.
This commit is contained in:
parent
63732aed0b
commit
bf1a32fdfc
1 changed files with 6 additions and 1 deletions
|
@ -2542,6 +2542,7 @@ if (isInputRange!RoR && isInputRange!(ElementType!RoR))
|
||||||
private:
|
private:
|
||||||
RoR _items;
|
RoR _items;
|
||||||
ElementType!RoR _current;
|
ElementType!RoR _current;
|
||||||
|
bool _valid_current;
|
||||||
void prepare()
|
void prepare()
|
||||||
{
|
{
|
||||||
for (;; _items.popFront())
|
for (;; _items.popFront())
|
||||||
|
@ -2550,6 +2551,7 @@ if (isInputRange!RoR && isInputRange!(ElementType!RoR))
|
||||||
if (!_items.front.empty) break;
|
if (!_items.front.empty) break;
|
||||||
}
|
}
|
||||||
_current = _items.front;
|
_current = _items.front;
|
||||||
|
_valid_current = true;
|
||||||
_items.popFront();
|
_items.popFront();
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
|
@ -2566,7 +2568,7 @@ if (isInputRange!RoR && isInputRange!(ElementType!RoR))
|
||||||
{
|
{
|
||||||
@property auto empty()
|
@property auto empty()
|
||||||
{
|
{
|
||||||
return _current.empty;
|
return !_valid_current || _current.empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@property auto ref front()
|
@property auto ref front()
|
||||||
|
@ -2614,6 +2616,9 @@ unittest
|
||||||
auto j = joiner(a);
|
auto j = joiner(a);
|
||||||
j.front() = 44;
|
j.front() = 44;
|
||||||
assert(a == [ [44, 2, 3], [42, 43] ]);
|
assert(a == [ [44, 2, 3], [42, 43] ]);
|
||||||
|
|
||||||
|
// bugzilla 8240
|
||||||
|
assert(equal(joiner([inputRangeObject("")]), ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
// uniq
|
// uniq
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue