title: Executing a specific function depend on type
body: <p>I want to make a function which can handle different kind of things depend on type all in one. </p>
  
  <p>I know Overloading is a nice solution for it. Just like, </p>
  
  <pre><code>class C1 {...};
  class C2 {...};    
  void handle(C1&amp; c1){...}
  void handle(C2&amp; c2){...}
  </code></pre>
  
  <p>But there are so many duplicated code in Overloading way since these 2  initialization is the same. That's why I want to wrap them together. </p>
  
  <p>I have some ideas for my purpose. 
  For example, </p>
  
  <pre><code>class C1 {...};
  class C2 {...};
  
  void handle_C1(C1 &amp;c1);
  void handle_C2(C2 &amp;c2);
  
  template&lt;typename T&gt;
  void handle(T &amp;content){
  // Initialization was done here
  if (std::is_same(C1, T))
     handle_C1(content);
  if (std::is_same(C2, T))
     handle_C2(content);
  }
  </code></pre>
  
  <p>A compilation error was found error that <strong>handle_C2 mismatch parameters</strong> because handle_C2 parameter type is C2 when I call </p>
  
  <pre><code>C1 c1;
  handle_C1&lt;C1&gt;(c1);
  </code></pre>
  
  <p>According to SFINAE in C++, I expect the compile would ignore this substitution failed, but it doesn't.  </p>
  
  <p>Is there anyone can give me a advice?  </p>
  
  <p>Is the best solution overloading? if it's true, how can I reduce my duplicated code. </p>