Skip to content

Commit a74854a

Browse files
committed
Merge pull request #58 from burner/dynamic_array_remove_back
removeBack for the DynamicArray
2 parents 3c6a439 + 615a39d commit a74854a

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/containers/dynamicarray.d

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,14 @@ struct DynamicArray(T, Allocator = Mallocator, bool supportGC = shouldAddGCRange
185185
}
186186
}
187187

188+
/**
189+
* Removes the last element from the array.
190+
*/
191+
void removeBack()
192+
{
193+
this.remove(this.length - 1);
194+
}
195+
188196
/// Index assignment support
189197
void opIndexAssign(T value, size_t i) @nogc
190198
{
@@ -386,4 +394,9 @@ unittest
386394
assert(arr2.length == 20);
387395
auto arr3 = arr2 ~ [100, 99, 98];
388396
assert(arr3.length == 23);
397+
398+
while(!arr3.empty)
399+
arr3.removeBack();
400+
assert(arr3.empty);
401+
389402
}

0 commit comments

Comments
 (0)