aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Chemeris <Alexander.Chemeris@gmail.com>2017-03-18 13:43:22 -0700
committerAlexander Chemeris <Alexander.Chemeris@gmail.com>2017-03-24 01:24:23 +0000
commitc708816be111b872f1793d48f04d5d926847dec2 (patch)
tree4ff903a4e28b21867762825cbd018b89963771b2
parente56bf3a0e526613b41095c2c6cbd546a219e812b (diff)
vector: Introduce segmentMove() method to move data inside of a vector.
-rw-r--r--CommonLibs/Vector.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/CommonLibs/Vector.h b/CommonLibs/Vector.h
index 38dc8d5..7062e17 100644
--- a/CommonLibs/Vector.h
+++ b/CommonLibs/Vector.h
@@ -222,6 +222,21 @@ template <class T> class Vector {
memcpy(other.mStart,base,span*sizeof(T));
}
+ /**
+ Move (copy) a segment of this vector into a different position in the vector
+ @param from Start point from which to copy.
+ @param to Start point to which to copy.
+ @param span The number of elements to copy.
+ */
+ void segmentMove(size_t from, size_t to, size_t span)
+ {
+ const T* baseFrom = mStart + from;
+ T* baseTo = mStart + to;
+ assert(baseFrom+span<=mEnd);
+ assert(baseTo+span<=mEnd);
+ memmove(baseTo,baseFrom,span*sizeof(T));
+ }
+
void fill(const T& val)
{
T* dp=mStart;