Bug 5011 – std.container: SList linearRemove produces wrong results

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-10-07T10:32:00Z
Last change time
2012-07-23T14:25:04Z
Keywords
patch
Assigned to
andrei
Creator
johannespfau

Comments

Comment #0 by johannespfau — 2010-10-07T10:32:11Z
If the first element of the Range passed to linearRemove(Take!Range r) is the SList root element all elements of Range are removed, not only the elements of Take!Range. Test case: import std.container; import std.range; void main() { auto s = SList!int(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); auto r = s[]; auto r1 = take(r, 4); assert(equal(r1, [1, 2, 3, 4])); auto r2 = s.linearRemove(r1); assert(s == SList!int(5, 6, 7, 8, 9, 10)); //fails } Solution: In the linearRemove(Take!Range r) function Range linearRemove(Take!Range r) { auto orig = r.original; // We have something to remove here if (orig._head == _root) { // remove straight from the head of the list for (; !orig.empty; orig.popFront()) The for line needs to be changed to: for (; !r.empty; r.popFront())
Comment #1 by ellery-newcomer — 2012-07-23T14:25:04Z