ericniebler / range-v3

Range library for C++14/17/20, basis for C++20's std::ranges
Other
4.11k stars 442 forks source link

Adding support for sizes/strides in slice. #1082

Open stefan-pdx opened 5 years ago

stefan-pdx commented 5 years ago

Hello,

I'm really excited about using range-v3 for a project of mine.

I have a use-case where I'd like to use range-v3 for iterating through multi-dimensional data, such as raster pixels in a std::vector<double>. There are times at which point I'd like to select pixels from a two-dimensional sub-region. The standard library provides a [gslice](https://en.cppreference.com/w/cpp/numeric/valarray/gslice) selector class that allows for iterating through values in a std::valarray by slice logic determined by multiple size/stride values.

As, cplusplus.com describes:

For example, a gslice with: start = 1 size = {2, 3} stride = {7, 2}

would select:

                    [0][1][2][3][4][5][6][7][8][9][10][11][12][13]
start=1:                *
                        |
size=2, stride=7:       *--------------------*
                        |                    |
size=3, stride=2:       *-----*-----*        *------*------*
                        |     |     |        |      |      |
gslice:                 *     *     *        *      *      *
                    [0][1][2][3][4][5][6][7][8][9][10][11][12][13]

Is there an existing way to compose this behavior with existing range views?

If not, would this proposed functionality warrant a new range view type called gslice?

Thanks!

dvirtz commented 5 years ago

I would be satisfied just with a stride in slice