56 m_container (numvalues) {} |
56 m_container (numvalues) {} |
57 |
57 |
58 Container (const C& other) : |
58 Container (const C& other) : |
59 m_container (other) {} |
59 m_container (other) {} |
60 |
60 |
|
61 Container(std::initializer_list<T> initializerList) : |
|
62 m_container(initializerList) {} |
|
63 |
61 T& append (const T& value) |
64 T& append (const T& value) |
62 { |
65 { |
63 m_container.push_back (value); |
66 m_container.push_back (value); |
64 return m_container[m_container.size() - 1]; |
67 return m_container[m_container.size() - 1]; |
|
68 } |
|
69 |
|
70 void append(const T* values, size_t numValues) |
|
71 { |
|
72 size_t i0 = size(); |
|
73 resize(size() + numValues); |
|
74 |
|
75 for (size_t i : range(numValues)) |
|
76 (*this)[i0 + i] = values[i]; |
65 } |
77 } |
66 |
78 |
67 Iterator begin() |
79 Iterator begin() |
68 { |
80 { |
69 return m_container.begin(); |
81 return m_container.begin(); |
254 void sort() |
266 void sort() |
255 { |
267 { |
256 std::sort (begin(), end()); |
268 std::sort (begin(), end()); |
257 } |
269 } |
258 |
270 |
259 Self splice (int a, int b) const |
271 Self splice(int start, int end, int step = 1) const |
260 { |
272 { |
261 if (a < 0 or b >= size() or b < a) |
273 start = clamp(start, 0, size() - 1); |
|
274 end = clamp(end, 0, size() - 1); |
|
275 |
|
276 if (end <= start) |
|
277 { |
262 return Self(); |
278 return Self(); |
263 |
279 } |
264 Self result; |
280 else |
265 |
281 { |
266 for (int i = a; i < b; ++i) |
282 Self result; |
267 result << operator[] (i); |
283 |
268 |
284 for (int i : range(start, end, step)) |
269 return result; |
285 result << operator[] (i); |
270 } |
286 |
271 |
287 return result; |
272 Self splice (const Range<int>& a) const |
288 } |
273 { |
289 } |
274 return splice (a.min(), a.max()); |
290 |
|
291 Self splice(Range<int>& range) const |
|
292 { |
|
293 return splice(range.min(), range.max(), range.step()); |
275 } |
294 } |
276 |
295 |
277 Self& operator<< (const T& value) |
296 Self& operator<< (const T& value) |
278 { |
297 { |
279 append (value); |
298 append (value); |
356 Super(numvalues){} |
375 Super(numvalues){} |
357 |
376 |
358 Vector (T* data, size_t length) : |
377 Vector (T* data, size_t length) : |
359 Super (std::vector<T> (data, data + length)) {} |
378 Super (std::vector<T> (data, data + length)) {} |
360 |
379 |
|
380 Vector(std::initializer_list<T> initializerList) : |
|
381 Super(initializerList) {} |
|
382 |
|
383 Vector(const Super& other) : |
|
384 Super(other) {} |
|
385 |
361 T* data() |
386 T* data() |
362 { |
387 { |
363 return Super::m_container.data(); |
388 return Super::m_container.data(); |
364 } |
389 } |
365 |
390 |