I want to force my compiler (C++ or perhaps CUDA) to unroll certain loops that it would rather not unroll. So, I've written the following:template <size_t N> struct unroller {    template <typename ForwardIterator, typename Function>    static void unroll(const Function& f, ForwardIterator& it) {        unroll<N/2, ForwardIterator, Function>(f, it);        ++it;        unroll<N-N/2, ForwardIterator, Function>(f, it);    }};template <> struct unroller<0> {    template <typename ForwardIterator, typename Function>    static void unroll(const Function& f, ForwardIterator& it) { }};template <> struct unroller<1> {    template <typename ForwardIterator, typename Function>    static void unroll(const Function& f, ForwardIterator& it) { f(it); }};I can also manually write in the instances at sizes 2,3,4 or so to perhaps reduce the amount of work the compiler needs to do. However, I was thinking maybe I should be doing something involving template packs and index lists to really cut down on the amount of instantiation. What do you think?Sample usage:#include <iostream>// unroller code hereint main(){    constexpr unsigned unroll_factor = 3;    constexpr unsigned total_iterations = 12;    static_assert(total_iterations % unroll_factor == 0,         Unroll factor must divide the number of iterations);    auto f = [](int n) { std::cout << n << ' ' << std::flush; };    std::cout << no manual unrolling: ;    for(int i = 0; i < total_iterations; i++) { f(i); }    std::cout << std::endl << manual unrolling x  << unroll_factor << : ;    for(int i = 0; i < total_iterations; i++) {        unroller<unroll_factor>::unroll(f, i);    }    std::cout << std::endl;    return 0;}
A generic manual loop unroller
c++;template