Skip to content

Commit 393029b

Browse files
committed
containers.dynamicarray: Implement opSliceAssign with arrays
1 parent 116a028 commit 393029b

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/containers/dynamicarray.d

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,20 @@ struct DynamicArray(T, Allocator = Mallocator, bool supportGC = shouldAddGCRange
378378
arr[i .. j] = value;
379379
}
380380

381+
/// ditto
382+
static if (isCopyable!T)
383+
void opSliceAssign(T[] values) @nogc
384+
{
385+
arr[0 .. l] = values[];
386+
}
387+
388+
/// ditto
389+
static if (isCopyable!T)
390+
void opSliceAssign(T[] values, size_t i, size_t j) @nogc
391+
{
392+
arr[i .. j] = values[];
393+
}
394+
381395
/// Returns: the number of items in the array
382396
size_t length() const nothrow pure @property @safe @nogc { return l; }
383397

@@ -696,3 +710,12 @@ version(emsi_containers_unittest) unittest
696710
arr.insertBack(1);
697711
assert(arr[0] == 1);
698712
}
713+
714+
version(emsi_containers_unittest) unittest
715+
{
716+
auto arr = DynamicArray!int();
717+
arr.resize(5);
718+
arr[] = [1, 2, 3, 4, 5];
719+
arr[1 .. 4] = [12, 13, 14];
720+
assert(arr[] == [1, 12, 13, 14, 5]);
721+
}

0 commit comments

Comments
 (0)