fork download
  1. #include <iostream>
  2. #include <utility>
  3.  
  4. template <bool b1, bool b2, bool b3, bool b4>
  5. void f()
  6. {
  7. std::cout << b1 << b2 << b3 << b4 << std::endl;
  8. }
  9.  
  10. template <std::size_t...Is>
  11. void call_f_helper(int i, std::index_sequence<Is...>)
  12. {
  13. using f_t = void();
  14. f_t* fs[] = {&f<(Is >> 0) & 1, (Is >> 1) & 1, (Is >> 2) & 1, (Is >> 3) & 1>...};
  15.  
  16. fs[i]();
  17. }
  18.  
  19.  
  20. void call_f(bool b1, bool b2, bool b3, bool b4)
  21. {
  22. call_f_helper(b1 << 0 | b2 << 1 | b3 << 2 | b4 << 3, std::make_index_sequence<16>());
  23. }
  24.  
  25.  
  26. int main()
  27. {
  28. for (int i = 0; i < 16; ++i) {
  29. call_f(i & 8, i & 4, i & 2, i & 1);
  30. }
  31. }
  32.  
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111