New extension: CCRange

Hello everybody,

Today I’m bringing you another extension, CCRange.
You can use it for creating ranges, similar to NSRange of Foundation Framework, but in object oriented way.

Note: read wiki for documentation.

Enjoy!

I’ve just took a quick look at it, but it would have sense to be able to iterate a range, right? (like in python). A macro for it and iterators (for C++11 range based loops) would be good for it :slight_smile:

I’ve never used ranges in that way, can you give me some examples please?
I have only used ranges for storing location and length of series of data, for example strings or arrays.
Thank you

Let r be a CCRange with location 0 and length 3.

Iterating r would mean to be able to do something with 0, 1 and 2.

Example:

for (unsigned int i = location; i < location + length; i++)
{
    // do something with i
}

This could be done with a macro:

unsigned int i;

CCRANGE_ITERATE(r, i)
{
    // do something
}

Or with C++11 iterators:

for (unsigned int i : r)
{
    // do something
}