Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are two problems here:</p> <ol> <li><code>enable_if</code> works with partial specialization, not primary templates.</li> <li>The number of externally-visible arguments is determined by the primary template, of which there may be only one.</li> </ol> <h1>Answer 1.</h1> <p>As you suggested in chat, a linked list of templates can emulate the variadic parameter pack.</p> <pre><code>template&lt;int I&gt; class X{ template&lt;class list, class = void&gt; struct Y; template&lt;class list&gt; struct Y&lt; list, typename std::enable_if&lt;I==1&gt;::type &gt; { typedef typename list::type t1; }; template&lt;class list&gt; struct Y&lt; list, typename std::enable_if&lt;I==2&gt;::type &gt; { typedef typename list::type t1; typedef typename list::next::type t2; }; }; </code></pre> <p>If you end up with <code>next::next::next</code> garbage, it's easy to write a metafunction, or use Boost MPL.</p> <hr> <h1>Answer 2.</h1> <p>The different-arity templates can be named similarly but still stay distinct if they are nested inside the SFINAE-controlled type.</p> <pre><code>template&lt;int I&gt; class X{ template&lt;typename = void, typename = void&gt; struct Z; template&lt;typename v&gt; struct Z&lt; v, typename std::enable_if&lt;I==1&gt;::type &gt; { template&lt;class T1&gt; struct Y{}; }; template&lt;typename v&gt; struct Z&lt; v, typename std::enable_if&lt;I==2&gt;::type &gt; { template&lt;class T1, class T2&gt; struct Y{}; }; }; X&lt;1&gt;::Z&lt;&gt;::Y&lt; int &gt; a; X&lt;2&gt;::Z&lt;&gt;::Y&lt; char, double &gt; b; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload