Speeduino
Loading...
Searching...
No Matches
static_for.hpp
Go to the documentation of this file.
1#pragma once
2
16#include <stdint.h>
17#include <utility>
18#include <initializer_list>
19
21namespace detail {
22
23template <typename F, uint8_t... Is>
24static inline __attribute__((always_inline)) void unroll_impl(F&& f, std::integer_sequence<uint8_t, Is...>) {
25 // C++14 expansion using an initializer list to evaluate f(Is) in order
26 (void)std::initializer_list<uint8_t>{ (f(std::integral_constant<uint8_t, Is>{}), (uint8_t)0)... };
27}
28
29} // detail
31
55template <uint8_t N, typename F>
56static inline __attribute__((always_inline)) void static_for(F&& f) {
57 detail::unroll_impl(std::forward<F>(f), std::make_integer_sequence<uint8_t, N>{});
58}
static void static_for(F &&f)
Generate a fixed number of calls to a given free function at compile time.
Definition static_for.hpp:56