Advertisement
Swiftkill

dispatcher

May 5th, 2021
713
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. template<int N>
  4. void foo() { std::cout << __PRETTY_FUNCTION__ << '\n'; }
  5.  
  6. template <int... Ns>
  7. decltype(auto) dispatch_foo(int const n, std::integer_sequence<int, Ns...>) {
  8.     static constexpr void (*_foos[])() { &foo<Ns>... };
  9.     return _foos[n]();
  10. }
  11.  
  12. template <int Nmax>
  13. decltype(auto) dispatch_foo(int const n) {
  14.     return dispatch_foo(n, std::make_integer_sequence<int, Nmax>{});
  15. }
  16.  
  17. int main() {
  18.     dispatch_foo<10>(3);
  19. }
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement