fork download
  1. #include <iostream>
  2. #include <utility>
  3. #include <vector>
  4.  
  5. template <int a, int b, int c> void foo() { std::cout << a << b << c << std::endl; }
  6.  
  7. template <std::size_t ... Is>
  8. void foo(int index, std::index_sequence<Is...>)
  9. {
  10. using f_type = void();
  11. f_type* f[] = {&foo<1 + Is / 16, 1 + (Is / 4) % 4, 1 + Is % 4>...};
  12.  
  13. f[index]();
  14. }
  15.  
  16. void foo(int a, int b, int c)
  17. {
  18. foo((a - 1) * 16 + (b - 1) * 4 + c - 1, std::make_index_sequence<64>());
  19. }
  20.  
  21.  
  22. int main()
  23. {
  24. foo(1, 1, 1);
  25. foo(1, 2, 3);
  26. foo(4, 4, 4);
  27. }
Success #stdin #stdout 0s 15256KB
stdin
Standard input is empty
stdout
111
123
444