aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Chemeris <Alexander.Chemeris@gmail.com>2017-03-18 14:08:43 -0700
committerAlexander Chemeris <Alexander.Chemeris@gmail.com>2017-03-24 01:25:06 +0000
commitf0189c47beb4ccfbbbb805d324d2b7bcb1092653 (patch)
tree9a25584b407fa8a5e4eccc4ab24b66594c639bca
parentc708816be111b872f1793d48f04d5d926847dec2 (diff)
vector: Introduce shrink() function to shrink vector size without loosing data.
-rw-r--r--CommonLibs/Vector.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/CommonLibs/Vector.h b/CommonLibs/Vector.h
index 7062e17..eae674b 100644
--- a/CommonLibs/Vector.h
+++ b/CommonLibs/Vector.h
@@ -92,6 +92,13 @@ template <class T> class Vector {
mEnd = mStart + newSize;
}
+ /** Reduce addressable size of the Vector, keeping content. */
+ void shrink(size_t newSize)
+ {
+ assert(newSize <= mEnd - mStart);
+ mEnd = mStart + newSize;
+ }
+
/** Release memory and clear pointers. */
void clear() { resize(0); }