support asArray for sorting items - for buggins/dlangide#250

This commit is contained in:
Vadim Lopatin 2017-09-07 10:53:18 +03:00
parent 27f170a7b9
commit cb8193f663
1 changed files with 10 additions and 3 deletions

View File

@ -324,10 +324,10 @@ struct ObjectList(T) {
}
}
/** remove and destroy all items */
void clear(bool destroyObj = true) {
void clear(bool destroyObj = true) {
for (int i = 0; i < _count; i++) {
if(destroyObj) {
destroy(_list[i]);
if(destroyObj) {
destroy(_list[i]);
}
_list[i] = null;
}
@ -343,6 +343,13 @@ struct ObjectList(T) {
}
return res;
}
/// Get items array slice. Don't try to resize it!
T[] asArray() {
if (!_count)
return null;
return _list[0.._count];
}
/// destructor destroys all items
~this() {
clear();
}