Utility Rack
All Classes Files Functions Modules Pages
repeat.hpp
Go to the documentation of this file.
1
23#ifndef REPEAT_HPP_INCLUDED
24#define REPEAT_HPP_INCLUDED
25
26#include <type_traits>
27
28namespace chops {
29
30template <typename F>
31constexpr auto repeat(int n, F&& f)
32 noexcept(noexcept(f(n)))
33 -> std::enable_if_t<std::is_invocable_v<F&&, int>>
34{
35 for(int i = 0; i < n; ++i)
36 {
37 f(i);
38 }
39}
40
41template <typename F>
42constexpr auto repeat(int n, F&& f)
43 noexcept(noexcept(f()))
44 -> std::enable_if_t<!std::is_invocable_v<F&&, int>>
45{
46 for(int i = 0; i < n; ++i)
47 {
48 f();
49 }
50}
51
52} // end namespace
53
54#endif
55