There is no C++11 way to do this without writing your own wrapper for it. An alternative option could be to use Range-V3 which has view::slice (see it live):
#include <iostream>
#include <range/v3/view.hpp>
int main() {
int arr[10] = {1,2,3,4,5,6,7,8,9,10} ;
using namespace ranges;
auto rng = arr | view::slice(3, 6);
for( auto &item : rng )
{
std::cout << item << ", " ;
}
std::cout << std::endl ;
}
If on the other hand C++14 was available then GSL array_view would be a viable option:
gsl::array_view<int> av(arr+3,3) ;
for( auto &item : av )
{
std::cout << item << ", " ;
}
std::cout << std::endl ;
gsl-lite offers a minimal GSL implementation that works in C++11.
forloop?