Advertisement
Guest User

Untitled

a guest
Nov 29th, 2015
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. template <typename Func, int LoopCounter>
  4. struct X
  5. {
  6. static void ForEach(Func func)
  7. {
  8. func(LoopCounter);
  9. X<Func, LoopCounter-1>::ForEach(func);
  10. }
  11. };
  12.  
  13. template <typename Func>
  14. struct X<Func, 0>
  15. {
  16. static void ForEach(Func func)
  17. {
  18. func(0);
  19. }
  20. };
  21.  
  22. int main()
  23. {
  24. const auto l = [] (const int i) { std::cout << "loop counter is " << i << std::endl; };
  25. X<decltype(l), 10>::ForEach(l);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement