Why isn’t a for-loop a compile-time expression?
Here’s a way to do it that does not need too much boilerplate, inspired from http://stackoverflow.com/a/26902803/1495627 : template<std::size_t N> struct num { static const constexpr auto value = N; }; template <class F, std::size_t… Is> void for_(F func, std::index_sequence<Is…>) { using expander = int[]; (void)expander{0, ((void)func(num<Is>{}), 0)…}; } template <std::size_t N, typename F> void for_(F … Read more