title: selecting appropriate copy-constructor based on template parameters
body: <p>I want to select implementation of a member function (copy constructor) based on a template argument value. I suppose there are two approaches: SFINAE and template partial specialization.</p>
  
  <p>The last one supposedly looks like this:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  template&lt;typename A, bool sw&gt;
  struct B
  {
      B() {}
      B(const B &amp;b);
  };
  
  template&lt;typename A&gt;
  B&lt;A, false&gt;::B(const B&lt;A, false&gt; &amp;b)
  {
      std::cout &lt;&lt; "false\n";
  }
  
  template&lt;typename A&gt;
  B&lt;A, true&gt;::B(const B&lt;A, true&gt; &amp;b)
  {
      std::cout &lt;&lt; "true\n";
  }
  
  int main()
  {
  }
  </code></pre>
  
  <p>It doesn't compile: <code>nested name specifier 'B&lt;A, false&gt;::' for declaration does not refer into a class, class template or class template partial specialization</code>.</p>
  
  <p>SFINAE approach fails too:</p>
  
  <pre><code>#include &lt;type_traits&gt;
  #include &lt;iostream&gt;
  
  template&lt;typename A, bool sw&gt;
  struct B
  {
      B() {}
  
      template&lt;typename U = typename std::enable_if&lt;sw, B&gt;::type&gt;
      B(const U &amp;b)
      {
          std::cout &lt;&lt; "true\n";
      }
  
      template&lt;typename U = typename std::enable_if&lt;!sw, B&gt;::type&gt;
      B(const U &amp;b)
      {
          std::cout &lt;&lt; "false\n";
      }
  };
  
  int main()
  {
      {
          B&lt;int, true&gt; b;
          auto bc = b; // cout &lt;&lt; true
      }
      {
          B&lt;int, false&gt; b;
          auto bc = b; // cout &lt;&lt; false
      }
  }
  </code></pre>
  
  <p>The compilation error here is <code>constructor cannot be redeclared</code> and <code>no type named 'type' in 'std::enable_if&lt;false, B&lt;int, false&gt; &gt;'; 'enable_if' cannot be used to disable this declaration</code>.</p>
  
  <p><em>Is there any way to fix the problems or otherwise select appropriate copy-constructor based on template parameters?</em></p>