Iterators for SparseSet

Have you considered adding iterator support to SparseSet? It would be very convenient to be able to use range-based for loops to iterate through all elements.

Well… yeah, could do, but not sure whether iterating a SparseSet makes a huge amount of sense.

Typically you’d use the class for very large sets where you have many repeated values, so iterating every single repeated item when there are probably vast numbers of them isn’t likely to be something a lot of people do. It may not even be something we should encourage… The operator is really there more for random access testing than for use in iteration.
You’d also not necessarily have values stored at every possible index, so even the idea of iterating from zero is probably also not something that’d make sense for all cases.

Thanks, Jules – it would be quite handy for the list box at least, since it returns the selection as a SparseSet.

1 Like

But you don’t generally iterate selections. Whenever I’ve used them, you tend to iterate your items and then random-access the selection to check whether each item has been selected or not.

Well, I guess I could go through every element and call isRowSelected. I would prefer to get the selection and iterate through it using a range based for loop for readability, but it’s definitely not a big deal.

Sure, but also there’s the possibility of creating something like a SparseSet<float>, which would be impossible to iterate.

Actually, just looking again at SparseSet, it’s a very old class that could use a bit of tightening-up in other ways, it might be worth us giving it a quick sanity-check.

3 Likes

Thanks!