Template Function wrench::unrolled_for¶
Defined in File unrolled_for.hpp
Function Documentation¶
-
template<size_t Amount, typename Functor, typename... Args> constexpr auto wrench::unrolled_for (Functor &&functor, Args &&... args) noexcept -> void
Applies the functor
Amount
times and passes the index of the unrolling as the first argument to the functor. The unrolling is performed at compile time, so the number of iterations should not be too large. The index parameter has a compile-time value, and can therefore be used in constexpr contexts, and can be converted tosize_t
as a constexpr expression. For example:auto tuple = std::make_tuple("string", 4, AType*()); unrolled_for<2>([&tuple] (auto i) { do_something(get<i>(tuple), get<i + 1>(tuple)); });
Which effectively will become:
do_something(get<0>(tuple), get<1>(tuple)); do_something(get<1>(tuple), get<2>(tuple));
- Note
This will cause code bloat if used often. Use this only in cases where compile time unrolling is required with a compile time index variable.
- Note
The functor must not return any value.
- Parameters
functor
: The functor to unroll.args
: The arguments to the functor.
- Template Parameters
Amount
: The amount of unrolling to do.Functor
: The type of the functor.Args
: The type of the functor arguments.