sources/list.h

changeset 179
7fc34735178e
parent 164
e3794f48a589
child 180
2e7225dbd9b2
--- a/sources/list.h	Wed Jan 27 12:38:00 2021 +0200
+++ b/sources/list.h	Wed Jan 27 13:02:51 2021 +0200
@@ -418,4 +418,24 @@
 ByteArray::ByteArray(Args&& ...args) :
     Vector<unsigned char>(args...) {}
 
+template<typename T>
+T splice(const T& container, int start, int end, int step = 1)
+{
+	start = clamp(start, 0, static_cast<int>(container.size()));
+	end = clamp(end, 0, static_cast<int>(container.size()));
+	T result;
+	result.reserve((end - start) / step);
+	for (int i = start; i < end; i += step)
+	{
+		result.push_back(container[i]);
+	}
+	return result;
+}
+
+template<typename T>
+T splice(const T& container, Range<int>& range)
+{
+	return splice(container, range.min(), range.max(), range.step());
+}
+
 END_ZFC_NAMESPACE

mercurial