summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/tanya/container/list.d44
1 files changed, 44 insertions, 0 deletions
diff --git a/source/tanya/container/list.d b/source/tanya/container/list.d
index cb3115f..9a5beb7 100644
--- a/source/tanya/container/list.d
+++ b/source/tanya/container/list.d
@@ -720,6 +720,50 @@ struct SList(T)
}
/**
+ * Removes the fron element of the $(D_PARAM range) from the list.
+ *
+ * Params:
+ * range = Range whose front element should be removed.
+ *
+ * Returns: $(D_PSYMBOL range) with the first element removed.
+ *
+ * Precondition: $(D_INLINECODE !range.empty).
+ * $(D_PARAM range) is extracted from this list.
+ */
+ Range popFirstOf(Range range)
+ in
+ {
+ assert(!range.empty);
+ assert(checkRangeBelonging(range));
+ }
+ do
+ {
+ auto next = (*range.head).next;
+
+ allocator.dispose(*range.head);
+ *range.head = next;
+
+ return range;
+ }
+
+ ///
+ @nogc nothrow pure @safe unittest
+ {
+ auto list = SList!int([5, 234, 30]);
+ auto range = list[];
+
+ range.popFront();
+ assert(list.popFirstOf(range).front == 30);
+
+ range = list[];
+ assert(range.front == 5);
+ range.popFront;
+ assert(range.front == 30);
+ range.popFront;
+ assert(range.empty);
+ }
+
+ /**
* Returns: Range that iterates over all elements of the container, in
* forward order.
*/