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:
k-hara 2012-06-15 13:23:15 +09:00
parent 63732aed0b
commit bf1a32fdfc

View file

@ -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