Advertisement
frasl

Untitled

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