www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21724] New: copy fails on overlapping ranges


          Issue ID: 21724
           Summary: copy fails on overlapping ranges
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: major
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: qs.il.paperinik gmail.com

When the spec says in https://dlang.org/spec/arrays.html, it demonstrates it
using overlapping arrays, but only in the case of copying later elements
(bigger index) to earlier elements (smaller index). In the case of the opposite
direction, copy does not produce the expected result.

The respective version of the example in the spec

    import std.algorithm;
    int[] s = [1, 2, 3, 4];

    copy(s[0..2], s[1..3]);
    assert(s == [1, 1, 2, 4]);

fails, because s == [1, 1, 1, 1].

Mar 16 2021