Advertisement
frasl

Untitled

Feb 11th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. template <typename T, int int_param> struct dispatch_demo {
  2.     void do_the_job_impl(int_v<0>)
  3.     {
  4.         std::cout << "zero" << std::endl;
  5.     }
  6.  
  7.     void do_the_job_impl(int_v<1>)
  8.     {
  9.         std::cout << "one" << std::endl;
  10.     }  
  11.  
  12.     template <int v> void do_the_job_impl(int_v<v>)
  13.     {
  14.         std::cout << "generic" << std::endl;
  15.     }
  16.  
  17.     void do_the_job()
  18.     {
  19.         do_the_job_impl(int_v<int_param>());
  20.     }
  21. };
  22.  
  23. int main() {
  24.     dispatch_demo<int, 0> d0;
  25.     dispatch_demo<int, 1> d1;
  26.     dispatch_demo<int, 2> d2;
  27.  
  28.     d0.do_the_job();
  29.     d1.do_the_job();
  30.     d2.do_the_job();
  31.  
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement