www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21099] New: std.container.array.Array should define

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

          Issue ID: 21099
           Summary: std.container.array.Array should define opSliceAssign
                    for multi-elements
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: zan77137 nifty.com

The following code should behave similarly to the built-in array:
------------------------------------------------
unittest {
    import std.container.array, std.algorithm;
    Array!ubyte ary;
    //ubyte[] ary;
    ary.length = 5;
    ubyte[] src = [1,2,3];
    // Error: none of the overloads of opSliceAssign are callable using
    // argument types(int[], int, int), candidates are:
    // Array!ubyte.Array.opSliceAssign(ubyte value)
    // Array!ubyte.Array.opSliceAssign(ubyte value, ulong i, ulong j)
    ary[1..4] = src[0..3];

    auto slice = ary[1..4];
    // Error: none of the overloads of opSliceAssign are callable using
    // argument types (ubyte[]), candidates are:
    // RangeT!(Array!ubyte).RangeT.opSliceAssign(ubyte value)
    // RangeT!(Array!ubyte).RangeT.opSliceAssign(ubyte value,ulong i,ulong j)
    slice[] = src[0..3];

    assert(ary[1..4].equal(src[0..3]));
    assert(slice[].equal(src[0..3]));
}
------------------------------------------------

There are two approaches to improve this.
1. Array and Range define opIndexAssign(T[], Range)
https://dlang.org/spec/operatoroverloading.html#slice_assignment_operator
2. Array and Range define opSliceAssign(T[] value, ulong i, ulong j) the legacy
way. 
https://digitalmars.com/d/1.0/operatoroverloading.html#Array

--
Aug 02 2020