http://d.puremagic.com/issues/show_bug.cgi?id=2975

           Summary: copy - source may exceed target
           Product: D
           Version: 2.030
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: patch
          Severity: minor
          Priority: P2
         Component: Phobos
        AssignedTo: [email protected]
        ReportedBy: [email protected]


Here is the current copy:

Range2 copy(Range1, Range2)(Range1 source, Range2 target)
    if (isInputRange!(Range1)
            && isOutputRange!(Range2, ElementType!(Range1)))
{
    foreach (e; source)
    {
        target.put(e);
    }
    return target;
}

When source has more elements than the target, it's possible to raise an
exception once target.empty is true.  I am unsure whether this is intended
behavior.

Here is what I think it should be:

Range2 copy(Range1, Range2)(Range1 source, Range2 target)
    if (isInputRange!(Range1)
            && isOutputRange!(Range2, ElementType!(Range1)))
{
    while ( !source.empty && !target.empty ) {
      target.put( source.front );
      source.popFront();
    }

    return target;
}

Is there a good reason to let copy proceed once target is exhausted?

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

Reply via email to