cuda::experimental::stf::make_tuple_indexwise
Defined in include/cuda/experimental/__stf/utility/core.cuh
-
template<size_t n, typename F, size_t... i>
constexpr auto cuda::experimental::stf::make_tuple_indexwise(F &&f, ::std::index_sequence<i...> = ::std::index_sequence<>()) Creates a
std::tuple
by applying a callable objectf
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 results of the calls are collected into astd::tuple
and returned. The callable object is expected to take a single argument of typestd::integral_constant<size_t, i>
, wherei
is the current index, and return a value of the desired type and value.If
f
returnsstd::ignore
for any argument(s), the corresponding value(s) will be skipped in the resulting tuple.Example usage:
auto make_double = [](auto index) { if constexpr (index == 2) return std::ignore; else return static_cast<double>(index); }; auto result = make_tuple_indexwise<5>(make_double); // result is std::tuple<double, double, double, double>{0.0, 1.0, 3.0, 4.0}
Note: Since this function is
constexpr
, it can be used at compile-time iff
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.
- Returns
A
std::tuple
containing the results of applyingf
to each integral constant in the range[0, n)
.