title: Template function: perform conversion based on typename
body: <p>Is there a way to achieve something like this in C++:</p>
  
  <pre><code>template&lt;typename T&gt;
  T function()
  {
      std::string result = getRes();
      // if (type == string)
          return result;
      // else if (type == numeric)
          return std::stoul(result, nullptr);
  }
  </code></pre>
  
  <p>Assuming the result variable type is always known (in this case string). The return type is defined by the template in the function call, e.g.:</p>
  
  <pre><code>int x = function&lt;int&gt;();
  </code></pre>
  
  <p>I know that there are things like <code>std::is_integral</code> or <code>std::is_same</code>. With those functions I could determine the type of T. However it does not seem to work, because it cannot be evaluated during compile time and therefore the compiler throws errors.</p>