#pragma once namespace Unroll { // Helper to force loop unrolling. Replace this: // // for (int i = 0; i < N; ++i) // { // WriteTo(&output[i]); // } // // with this: // // For<0,N>::Do([&](int i) // { // WriteTo(&output[i]); // }); // template struct For { // Take func by const& instead && because we need to support both // lvalues (like named functions) and rvalues (like lambdas), but // it makes no sense to move/forward rvalues since func is called // multiple times. template static void Do(Func const& func, int i = From) { func(i); For::Do(func, i + 1); } }; template struct For { template static void Do(Func const&, int) {} }; } // namespace Unroll