www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5011] New: std.container: SList linearRemove produces wrong results

reply d-bugmail puremagic.com writes:
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 puremagic.com
        ReportedBy: johannespfau gmail.com


--- Comment #0 from Johannes Pfau <johannespfau 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: -------
Oct 07 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5011


Andrei Alexandrescu <andrei metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |andrei metalanguage.com
         AssignedTo|nobody puremagic.com        |andrei metalanguage.com


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 09 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5011


Ellery Newcomer <ellery-newcomer utulsa.edu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
                 CC|                            |ellery-newcomer utulsa.edu
         Resolution|                            |FIXED


--- Comment #1 from Ellery Newcomer <ellery-newcomer utulsa.edu> 2012-07-23
14:25:04 PDT ---
https://github.com/D-Programming-Language/phobos/commit/64c5e3cffa58fecdb8ecb23fd175e5b8dcede2a7

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 23 2012