[Issue 21724] New: copy fails on overlapping ranges

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Mar 17 01:36:24 UTC 2021


https://issues.dlang.org/show_bug.cgi?id=21724

          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 at puremagic.com
          Reporter: qs.il.paperinik at 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].

--


More information about the Digitalmars-d-bugs mailing list