[Issue 2975] New: copy - source may exceed target

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed May 13 12:55:33 PDT 2009


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: bugzilla at digitalmars.com
        ReportedBy: k-foley at onu.edu


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


More information about the Digitalmars-d-bugs mailing list