Index Range¶
An IndexRange
(source) represents a set of non-negative consecutive indices. It's stored as just the start index and the number of indices. Since it's small, it should generally be passed by value.
The most common usage of IndexRange
is to loop over indices. This is better than a c-style index loop because it reduces the likelyhood of mixing up variables and allows the current index to be const. It's also just more convenient.
Most container data structures have an .index_range()
method which makes it easy to iterate over all the indices in the container.