Skip to content

Commit

Permalink
Merge pull request #187 from CyberShadow/pull-20210922-173345
Browse files Browse the repository at this point in the history
containers.dynamicarray: Implement opSliceAssign with arrays
  • Loading branch information
PetarKirov authored Sep 24, 2021
2 parents 26acc66 + 393029b commit 31be25a
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/containers/dynamicarray.d
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,20 @@ struct DynamicArray(T, Allocator = Mallocator, bool supportGC = shouldAddGCRange
arr[i .. j] = value;
}

/// ditto
static if (isCopyable!T)
void opSliceAssign(T[] values) @nogc
{
arr[0 .. l] = values[];
}

/// ditto
static if (isCopyable!T)
void opSliceAssign(T[] values, size_t i, size_t j) @nogc
{
arr[i .. j] = values[];
}

/// Returns: the number of items in the array
size_t length() const nothrow pure @property @safe @nogc { return l; }

Expand Down Expand Up @@ -696,3 +710,12 @@ version(emsi_containers_unittest) unittest
arr.insertBack(1);
assert(arr[0] == 1);
}

version(emsi_containers_unittest) unittest
{
auto arr = DynamicArray!int();
arr.resize(5);
arr[] = [1, 2, 3, 4, 5];
arr[1 .. 4] = [12, 13, 14];
assert(arr[] == [1, 12, 13, 14, 5]);
}

0 comments on commit 31be25a

Please sign in to comment.