Bug 21099 – std.container.array.Array should define opSliceAssign for multi-elements

Status
NEW
Severity
enhancement
Priority
P4
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-08-02T08:29:05Z
Last change time
2024-12-01T16:37:25Z
Assigned to
No Owner
Creator
SHOO
Moved to GitHub: phobos#10432 →

Comments

Comment #0 by zan77137 — 2020-08-02T08:29:05Z
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
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10432 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB