summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2017-01-03 13:21:19 +0100
committerEugen Wissner <belka@caraus.de>2017-01-03 13:21:19 +0100
commit67952dabdb28e504cdc0e34c9f7151e7ffb71ff2 (patch)
tree5e3306176c3905d8f591cfa8650d261bff5ef127
parentb8d5d4c2bd1e8b9637782b36b8ccbafd2785070e (diff)
downloadtanya-67952dabdb28e504cdc0e34c9f7151e7ffb71ff2.tar.gz
Implement Vector.remove
-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: