title: C++ Template is sending a "false argument" a bad practice?
body: <p>std::stoi is throwing some errors in specific cases. I don't want to use try/catch block, so I googled a little bit about char convertion and saw that <code>std::from_chars</code> was doing exactly what I wanted, without those try/catch block.</p>
  <p>Obviously, using <code>std::from_chars</code> directly works pretty well, but I don't like the syntax. So I started writing my own <code>ToInt()</code>, <code>ToFloat()</code>, etc. And was like : &quot;ok, that sounds stupid, let's use template&quot;.</p>
  <p>Here I am :</p>
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;string&gt;
  #include &lt;charconv&gt;
  #include &lt;iostream&gt;
  
  template &lt;typename T&gt;
  T ToNumber(const char* str, T varType)
  {
      if (!str)
          return 0;
      T var = 0;
      std::from_chars(str, str + strlen(str), var);
      return var;
  }
  
  int main()
  {
      std::string t = &quot;123.5&quot;;
  
      auto a = ToNumber(t.c_str(), (int)0); // a will be an int (123)
      float b = ToNumber(t.c_str(), (int)0); // b will store the value as int (123)
      auto c = ToNumber(t.c_str(), (float)0); // c will be a float (123.5)
  
      std::cout &lt;&lt; a;
      return 0;
  }
  </code></pre>
  <p>It actually works, that is not the problem. But I was wondering... Is it a good practice to send a &quot;false argument&quot; (<code>T varType</code>) in order to get the cast done and enable <code>auto</code> ?</p>
  <p>If not, what is the clever way to write such a function ?</p>
  <p>Thanks in advance</p>