This series of two articles covers the train of thought behind the design and implementation of a simple `repeat` abstraction that, given a number `n` and a function object `f`, invokes `f` `n` times. The abstraction can be used to repeat actions both at run-time and compile-time. The articles also cover importance of propagating `noexcept`-correctness (and the pain caused by it!).
abstraction design and implementation: `repeat`
compile-time `repeat` & `noexcept`-correctness
by Vittorio Romeo
From the articles:
In my previous "passing functions to functions" and "zero-overhead C++17 currying & partial application" articles I've praised C++11 (and newer standards) for allowing us to write "more functional" code. [...] If I want to repeat an action n times, I exactly want to write that in my code:
repeat(10, []
{
foo();
});Cannot get simpler than that - let's implement it!
Add a Comment
Comments are closed.