title: SFINAE with enable_if and overloading
body: <p>I've done some looking around, but was unable to find a solution to my specific problem.</p>
  
  <p>I have the code:</p>
  
  <pre><code>template &lt;typename T&gt;
  typename std::enable_if&lt;std::is_arithmetic&lt;T&gt;::value || std::is_enum&lt;T&gt;::value, std::string&gt;::type
      convertToString(const T argument) { return std::to_string(argument); }
  
  std::string convertToString(std::string string);
  </code></pre>
  
  <p>What the code is supposed to do: Use the template version for any numeric type (int, float, double and also ENum) and use the std::string version for anything else.</p>
  
  <p>The code itself compiles fine, however when I pass the function a class, which has a <code>operator const char *</code> overload (which is a viable constructor for <code>std::string</code>), it throws me the following bulk of messages:</p>
  
  <pre><code>no matching function for call to 'SQL_Connection::convertToString(ClassName &amp;)’
  
  candidate: template&lt;class T&gt; typename std::enable_if&lt;(std::is_arithmetic&lt;_Tp&gt;::value || std::is_enum&lt;_Tp&gt;::value), std::__cxx11::basic_string&lt;char&gt; &gt;::type convertToString(T)
   convertToString(const T argument) { return std::to_string(argument); }
   ^~~~~~~~~~~~~~~
  
  template argument deduction/substitution failed:
  In substitution of ‘template&lt;class T&gt; typename std::enable_if&lt;(std::is_arithmetic&lt;_Tp&gt;::value || std::is_enum&lt;_Tp&gt;::value), std::__cxx11::basic_string&lt;char&gt; &gt;::type convertToString(T) [with T = ClassName]’:
  </code></pre>
  
  <p>I've been trying to wrap my head around <code>enable_if</code> and what it does, but at this point I find myself stumped.</p>
  
  <p>Why isn't it falling back to the <code>std::string</code> overload, when it clearly is neither arithmetic nor an ENum?</p>
  
  <p>If I explicitly convert the object to string or const char *, it works as expected.</p>
  
  <p>Thank you very much for your help.</p>
  
  <p>Additional info: I'm using C++11 and g++ 7.3.0 on an Ubuntu system.</p>