Is there any way to do a range-based for loop of part of a vector? For instance, I'd like to iterate over the first 5 elements of the vector:
for(auto& elem : my_vector[0:5]) { // Syntax obviously doesn't exist
do_stuff(elem);
}
I could write my own container as specified in How to make my custom type to work with "range-based for loops"? but I'm hoping that there is an easier way in boost or some related library.
C++20 appears to include "ranges", but is there anything similar before 20?