Utility Rack
Loading...
Searching...
No Matches
repeat.hpp File Reference

Repeat code N times, since the C++ standard range-for does not make it easy to repeat a loop N times. The lambda or function object can access the iteration count, if desired. More...

#include <type_traits>
Include dependency graph for repeat.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

template<typename F >
constexpr auto chops::repeat (int n, F &&f) noexcept(noexcept(f(n))) -> std::enable_if_t< std::is_invocable_v< F &&, int > >
 

Detailed Description

Repeat code N times, since the C++ standard range-for does not make it easy to repeat a loop N times. The lambda or function object can access the iteration count, if desired.

This code is copied from Vittorio Romeo's blog at https://vittorioromeo.info/, specifically the first article in the series: https://vittorioromeo.info/index/blog/abstraction_design_implementation_repeat.html. This is the same as his, including the noexcept propagation, except that it has been simplified so that the count type is not simplified. Vittorio has written another article showing a compile-time repeat function.

Authors
Vittorio Romeo, Cliff Green

Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)