title: C++ Template Branching
body: <p>I have an interesting case of trying to have branch within a template function where the path is dependent on the interface implemented by the template type. This branch then determines the constructor of the return value. I am unsure if this type of branching is possible. The alternative it to split the function into two different function and have the user call the one that corresponds to the desired branch.</p>
  
  <p>My question is twofold:</p>
  
  <p><strong>How can I perform the if statement based on the interface implementation?</strong></p>
  
  <p><strong>How can I get the function to compile when the interface is not implemented?</strong> For example <code>int</code> does not have a constructor with two parameters.</p>
  
  <pre><code>template&lt;typename T&gt;
  T GetObject()
  {
      // If T implements interface, call interface constructor
      if(typeid(T) implements inteface IInterface) // How can this be done?
          return T(1, 2);
  
      // If T does not implement the interface, call parameterless constructor
      else
          return T();
  }
  </code></pre>