Template Function poet::dynamic_for(std::size_t, Func&&, Args…)

Function Documentation

template<std::size_t Unroll, std::ptrdiff_t Step = 1, typename Func, typename ...Args, std::enable_if_t<detail::has_hot_args_v<Args...> && detail::is_df_callable_v<std::remove_reference_t<Func>, std::size_t, Args...>, int> = 0>
void poet::dynamic_for(std::size_t count, Func &&func, Args... args)

Executes a runtime-sized loop over [0, count), passing loop-invariant “hot” values to the callable by value instead of through a closure.

GCC does not scalar-replace a capturing lambda’s closure that holds large types (AVX-512 zmm values, say): the closure spills to the stack and reloads once per iteration even with full inlining. Named by-value parameters stay in registers.

This form requires at least one hot argument, so a zero-arg call still selects the (count, func) overload.

Template Parameters:
  • Unroll – Iterations per unrolled block.

  • Step – Compile-time stride (must be non-zero).

Parameters:
  • count – Iteration count, i.e. the range [0, count).

  • func – Callable void(T index, HotArgs...). Do not also capture the hot values; a capture would reintroduce the closure this form avoids.

  • args – Loop-invariant values forwarded by value at each level.