summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/tanya/container/vector.d45
1 files changed, 45 insertions, 0 deletions
diff --git a/source/tanya/container/vector.d b/source/tanya/container/vector.d
index 0e67b54..0992733 100644
--- a/source/tanya/container/vector.d
+++ b/source/tanya/container/vector.d
@@ -644,6 +644,51 @@ struct Vector(T)
}
/**
+ * Remove all elements beloning to $(D_PARAM r).
+ *
+ * Params:
+ * r = Range originally obtained from this vector.
+ *
+ * Returns: Elements in $(D_PARAM r) after removing.
+ */
+ Range!T remove(Range!T r) @trusted
+ in
+ {
+ assert(r.begin >= vector && r.end <= vector + length_);
+ }
+ body
+ {
+ const T* end = vector + length_;
+ for (T* a = r.begin, b = r.end; b != end; ++a, ++b)
+ {
+ *a = *b;
+ }
+ length_ -= r.length;
+ return r;
+ }
+
+ ///
+ unittest
+ {
+ auto v = Vector!int(IL(5, 18, 17, 2, 4, 6, 1));
+
+ v.remove(v[1..3]);
+ assert(v == Vector!int(IL(5, 2, 4, 6, 1)));
+
+ v.remove(v[4..4]);
+ assert(v == Vector!int(IL(5, 2, 4, 6, 1)));
+
+ v.remove(v[4..5]);
+ assert(v == Vector!int(IL(5, 2, 4, 6)));
+
+ v.remove(v[]);
+ assert(v.empty);
+
+ v.remove(v[]);
+ assert(v.empty);
+ }
+
+ /**
* Inserts the $(D_PARAM el) into the vector.
*
* Params: