Self-unrolling macro loop in C/C++

You can use templates to unroll. See the disassembly for the sample Live on Godbolt But -funroll-loops has the same effect for this sample. Live On Coliru template <unsigned N> struct faux_unroll { template <typename F> static void call(F const& f) { f(); faux_unroll<N-1>::call(f); } }; template <> struct faux_unroll<0u> { template <typename F> static … Read more