Loop over whole array starting from any index I recently had to repeatedly iterate over an array but increment the index to start from each time. Since this is quite cumbersome in comparison to a normal for loop I made a small template function that does this for me:

#include &lt;algorithm&gt;
#include &lt;iostream&gt;

template&lt;typename TSize, typename TFunc&gt;
void for_start(const TSize start, const TSize size, TFunc&amp;&amp; fn)
{
    for(TSize c{}, i{c + start}; c &lt; size; ++c, ++i)
    {
        if(i &gt;= size)
            i = 0;
        fn(i);
    }
}

template&lt;typename TRAIter, typename TFunc&gt;
void for_start(TRAIter start, TRAIter begin, TRAIter end, TFunc&amp;&amp; fn)
{
    for(TRAIter c{begin}, i{c + std::distance(begin, start)}; c != end; ++i, ++c)
    {
        if(i == end)
            i = begin;

        fn(i);
    }
}

// usage
int main()
{
    const unsigned ARR_SIZE{10};
    int arr[ARR_SIZE]{
        0, 1, 2, 3, 4, 5, 6, 7, 8, 9
    };


    for_start(5u, ARR_SIZE, [arr](unsigned i)
    {
        std::cout &lt;&lt; arr[i] &lt;&lt; ' ';
    });
    std::cout &lt;&lt; '\n';

    for_start(std::begin(arr) + 5, std::begin(arr), std::end(arr), [](const int* i)
    {
        std::cout &lt;&lt; *i &lt;&lt; ' ';
    });
}

// prints:
// 5 6 7 8 9 0 1 2 3 4 
// 5 6 7 8 9 0 1 2 3 4 


I'd like to get some feedback on things like usability (function name, order of parameters) and reuseability. Note that I'd like to use this function with signed &amp; unsigned integers.
There is no reason to initialize i as {c + std::distance(begin, start)}. Upon such initialization you are guaranteed that i == start. A much simpler i{start} suffices.
Testing for i == size, or i == end inside the loop, as well as tracking two iterators, feels wasteful. Consider splitting the loop into two, e.g:

    for (i = start; i != end; ++i) {
        fn(i);
    }

    for (i = begin; i != start; ++i) {
        fn(i);
    }

I am not sure that for_start is a good name. I am also not sure what name would be good. iterate_rotated perhaps?