Template Function ripple::unrolled_for¶
Function Documentation¶
-
template<size_t
Amount
, typenameFunctor
, typename ...Args
>
constexpr autoripple
::
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, otherwise this will cause code bloat.
The index parameter has a compile-time value, and can therefore be used in constexpr contexts. 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
If it’s required that the unrolling is bounded, then use the
unrolled_for_bounded
.- 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.