Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- template <typename Func, int LoopCounter>
- struct X
- {
- static void ForEach(Func func)
- {
- func(LoopCounter);
- X<Func, LoopCounter-1>::ForEach(func);
- }
- };
- template <typename Func>
- struct X<Func, 0>
- {
- static void ForEach(Func func)
- {
- func(0);
- }
- };
- int main()
- {
- const auto l = [] (const int i) { std::cout << "loop counter is " << i << std::endl; };
- X<decltype(l), 10>::ForEach(l);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement