How to remove certain portion of elements(QList)
I need some function which would allow me do something like that:
items.removeFromTo(157, 2877); //remove all elements between 157 and 2877
I need to use such a function numerous times, so do that manually for every element through loop worst idea.
Found one: erase(from, to);
QListdoes not have a "range delete" method. Items will have to be removed in a loop. I don't know why you need to do numerous range deletions, or whether you've actually timed these. Would
QVectorwith its http://doc.qt.io/qt-5/qvector.html#remove-1
remove(int i, int count)have been a better choice? Or some other data structure?
@JonB why then at doc in description:
Removes all the items from begin up to (but not including) end. Returns an iterator to the same item that end referred to before the call.
You are quite right! I spotted
remove(), and noticed that
QListdid not offer a
countoverload, but did not occur to me to look for
I still wonder though:
so do that manually for every element through loop worst idea.
Erasing from a list still requires visiting each element, so I would have thought that
erase()will simply be of the same order as looping through each element anyway.