title: SFINAE for constructor parameters
body: <p>I'm trying to create a sample class which has different specializations according to whether its template parameter can be constructed with certain parameters. In my sample, with a simple <code>int</code>. I've tried with:</p>
  
  <pre><code>template&lt;class A_t&gt;
  struct creator
  {
      A_t* ptr = nullptr;
  };
  
  template&lt;class A_t&gt;
  struct creator&lt;decltype(A_t(int()))&gt;
  {
      A_t* ptr = new A_t(5);
  };
  
  struct A
  {
      int i;
  
      A(int i) : i(i) {}
  };
  
  int main() {
      std::cout &lt;&lt; creator&lt;A&gt;().ptr &lt;&lt; std::endl;
  
      return 0;
  }
  </code></pre>
  
  <p>My intention is that it prints a memory address of a automatically constructed object. However, it is printing a 0. So, it's taking the non-specialized template.</p>
  
  <p><code>A_t</code> is deducible with that syntax, among other things because <code>A_t</code> is given explicitly. Besides, <code>decltype(A_t(int())</code> has type <code>A_t</code> (and not <code>A_t&amp;&amp;</code> for example), a simple test:</p>
  
  <pre><code>std::cout &lt;&lt; std::is_same&lt;decltype(A(int()), A&gt;::value &lt;&lt; std::endl;
  </code></pre>
  
  <p>prints 1.</p>
  
  <p>However, that implementation works:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  template&lt;class A_t, class = A_t&gt;
  struct creator
  {
      A_t* ptr = nullptr;
  };
  
  template&lt;class A_t&gt;
  struct creator&lt;A_t, decltype(A_t(int()))&gt;
  {
      A_t* ptr = new A_t(5);
  };
  
  struct A
  {
      int i;
  
      A(int i) : i(i) {}
  };
  
  int main() {
      std::cout &lt;&lt; creator&lt;A&gt;().ptr &lt;&lt; std::endl;
  
      return 0;
  }
  </code></pre>
  
  <p><a href="http://coliru.stacked-crooked.com/a/d3bfa27026028b2e" rel="nofollow noreferrer">Coliru</a> test with two classes, one accepting an <code>int</code> as parameter, and other which doesn't.</p>
  
  <p>Why is the first approach not working?</p>