cuda::experimental::stf::unroll#

template<size_t n, typename F, size_t... i>
constexpr void cuda::experimental::stf::unroll(
F &&f,
::std::index_sequence<i...> = {},
)#

Applies a callable object f to each integral constant within a given range [0, n).

This function template takes a callable object f and applies it to each integral constant in the range [0, n). The callable object is expected to take a single argument of type std::integral_constant<size_t, i> (or size_t), where i is the current index.

The important element is that the lambda can use its integral argument during compilation, e.g. to fetch a tuple element with std::get<i>(t).

Example usage:

auto print_index = [](auto index) { ::std::cout << index << ' '; };
unroll<5>(print_index); // Output: 0 1 2 3 4

Note: Since this function is constexpr, it can be used at compile-time if f is a compile-time invocable object.

Template Parameters:
  • n – The number of times the callable object f should be applied.

  • F – Type of the callable object.

  • i... – (Internal) Indices for parameter pack expansion.

Parameters:

f – The callable object to apply to each integral constant.