title: Metaprograming: Failure of Function Definition Defines a Separate Function
body: <p>In <a href="https://stackoverflow.com/a/30167800/2642059">this answer</a> I define a template based on the type's <code>is_arithmetic</code> property:</p>
  
  <pre><code>template&lt;typename T&gt; enable_if_t&lt;is_arithmetic&lt;T&gt;::value, string&gt; stringify(T t){
      return to_string(t);
  }
  template&lt;typename T&gt; enable_if_t&lt;!is_arithmetic&lt;T&gt;::value, string&gt; stringify(T t){
      return static_cast&lt;ostringstream&amp;&gt;(ostringstream() &lt;&lt; t).str();
  }
  </code></pre>
  
  <p><a href="https://stackoverflow.com/questions/30166706/c-convert-simple-values-to-string/30167800#comment48447560_30167455">dyp suggests</a> that rather than the <code>is_arithmetic</code> property of the type, that whether <code>to_string</code> is defined for the type be the template selection criteria. This is clearly desirable, but I don't know a way to say:</p>
  
  <blockquote>
    <p>If <code>std::to_string</code> is not defined then use the <code>ostringstream</code> overload.</p>
  </blockquote>
  
  <p>Declaring the <code>to_string</code> criteria is simple:</p>
  
  <pre><code>template&lt;typename T&gt; decltype(to_string(T{})) stringify(T t){
      return to_string(t);
  }
  </code></pre>
  
  <p>It's the opposite of that criteria that I can't figure out how to construct. This obviously doesn't work, but hopefully it conveys what I'm trying to construct:</p>
  
  <pre><code>template&lt;typename T&gt; enable_if_t&lt;!decltype(to_string(T{})::value, string&gt; (T t){
      return static_cast&lt;ostringstream&amp;&gt;(ostringstream() &lt;&lt; t).str();
  }
  </code></pre>