sources/list.h

changeset 157
42bb29924218
parent 148
19e98695e584
child 158
de7574d292ad
--- a/sources/list.h	Wed Jul 20 22:56:16 2016 +0300
+++ b/sources/list.h	Fri Jul 22 17:50:00 2016 +0300
@@ -58,12 +58,24 @@
 	Container (const C& other) :
 		m_container (other) {}
 
+	Container(std::initializer_list<T> initializerList) :
+	    m_container(initializerList) {}
+
 	T& append (const T& value)
 	{
 		m_container.push_back (value);
 		return m_container[m_container.size() - 1];
 	}
 
+	void append(const T* values, size_t numValues)
+	{
+		size_t i0 = size();
+		resize(size() + numValues);
+
+		for (size_t i : range(numValues))
+			(*this)[i0 + i] = values[i];
+	}
+
 	Iterator begin()
 	{
 		return m_container.begin();
@@ -256,22 +268,29 @@
 		std::sort (begin(), end());
 	}
 
-	Self splice (int a, int b) const
+	Self splice(int start, int end, int step = 1) const
 	{
-		if (a < 0 or b >= size() or b < a)
-			return Self();
+		start = clamp(start, 0, size() - 1);
+		end = clamp(end, 0, size() - 1);
 
-		Self result;
+		if (end <= start)
+		{
+			return Self();
+		}
+		else
+		{
+			Self result;
 
-		for (int i = a; i < b; ++i)
-			result << operator[] (i);
+			for (int i : range(start, end, step))
+				result << operator[] (i);
 
-		return result;
+			return result;
+		}
 	}
 
-	Self splice (const Range<int>& a) const
+	Self splice(Range<int>& range) const
 	{
-		return splice (a.min(), a.max());
+		return splice(range.min(), range.max(), range.step());
 	}
 
 	Self& operator<< (const T& value)
@@ -358,6 +377,12 @@
 	Vector (T* data, size_t length) :
 		Super (std::vector<T> (data, data + length)) {}
 
+	Vector(std::initializer_list<T> initializerList) :
+	    Super(initializerList) {}
+
+	Vector(const Super& other) :
+		Super(other) {}
+
 	T* data()
 	{
 		return Super::m_container.data();

mercurial