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
Comment #1 by robert.schadek — 2024-12-01T16:37:25Z