ericniebler / range-v3

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

[request] Binding range in ranges::at or ranges::index #1607

Open beojan opened 3 years ago

beojan commented 3 years ago

As a result of working with struct-of-arrays layout data, I often find I want to work with indices instead of the data itself (i.e. with argsort / argmax type functions).

Range-v3 already makes this quite easy since you simply have to use a projector of the form [&rng](std::size_t i){return rng[i];} or [&rng](std::size_t i){return rng.at(i);}. However, I think this could be improved by providing the ability to construct a ranges::at_fn or ranges::index_fn with the range bound, which could then be used to index into that range.