[Issue 5011] New: std.container: SList linearRemove produces wrong results
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Oct 7 10:32:36 PDT 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5011
Summary: std.container: SList linearRemove produces wrong
results
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: Phobos
AssignedTo: nobody at puremagic.com
ReportedBy: johannespfau at gmail.com
--- Comment #0 from Johannes Pfau <johannespfau at gmail.com> 2010-10-07 10:32:11 PDT ---
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())
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list