Note that there are some explanatory texts on larger screens.

plurals
  1. POIs this a compiler bug or a programmer bug?
    primarykey
    data
    text
    <p>I'm playing with tuples as compile time lists. In <a href="https://stackoverflow.com/questions/9831501/how-can-i-have-multiple-parameter-packs-in-a-variadic-template">How can I have multiple parameter packs in a variadic template?</a> I answered myself with some code that works in both GCC and Clang, but Clang wont compile now that I've added (what I think is) perfect forwarding. It complains that <code>As...</code> and <code>as...</code> have different lengths in <code>std::forward&lt;As&gt;(as)...</code>. How can this be true when <code>As...</code> is the type of <code>as...</code>? It's <code>As&amp;&amp;... as</code> in the parameters.</p> <pre><code>#include &lt;iostream&gt; #include &lt;tuple&gt; template &lt; typename ... &gt; struct two_impl {}; // Base case template &lt; typename F, typename ...Bs &gt; struct two_impl &lt; F, std::tuple &lt;&gt;, std::tuple&lt; Bs... &gt; &gt; { void operator()(F&amp;&amp; f, Bs&amp;&amp;... bs) { f(std::forward&lt;Bs&gt;(bs)...); } }; // Recursive case template &lt; typename F, typename A, typename ...As, typename ...Bs &gt; struct two_impl &lt; F, std::tuple&lt; A, As... &gt;, std::tuple&lt; Bs...&gt; &gt; { void operator()(F&amp;&amp; f, A&amp;&amp; a, As&amp;&amp;... as, Bs&amp;&amp;... bs) { auto impl = two_impl &lt; F, std::tuple &lt; As&amp;&amp;... &gt;, std::tuple &lt; Bs&amp;&amp;..., A&amp;&amp; &gt; &gt;(); impl(std::forward&lt;F&gt;(f), std::forward&lt;As&gt;(as)..., std::forward&lt;Bs&gt;(bs)..., std::forward&lt;A&gt;(a)); } }; template &lt; typename F, typename ...Ts &gt; void two(F&amp;&amp; f, Ts&amp;&amp; ...ts) { auto impl = two_impl&lt; F, std::tuple &lt; Ts... &gt;, std::tuple &lt;&gt; &gt;(); impl(std::forward&lt;F&gt;(f), std::forward&lt;Ts&gt;(ts)...); } struct Test { void operator()(int i, float f, double d) { std::cout &lt;&lt; i &lt;&lt; std::endl &lt;&lt; f &lt;&lt; std::endl &lt;&lt; d &lt;&lt; std::endl; } }; int main () { two(Test(), 1, 1.5f, 2.1); } </code></pre> <p>Compiling with <code>clang -lstdc++ -std=c++0x multiple_parameter_packs.cpp</code></p> <pre><code>clang -lstdc++ -std=c++0x multiple_parameter_packs.cpp multiple_parameter_packs.cpp:24:50: error: pack expansion contains parameter packs 'As' and 'as' that have different lengths (1 vs. 2) impl(std::forward&lt;F&gt;(f), std::forward&lt;As&gt;(as)..., std::forward&lt;Bs&gt;(bs)..., std::forward&lt;A&gt;(a)); ~~ ~~ ^ multiple_parameter_packs.cpp:24:5: note: in instantiation of member function 'two_impl&lt;Test, std::tuple&lt;float &amp;&amp;, double &amp;&amp;&gt;, std::tuple&lt;int &amp;&amp;&gt; &gt;::operator()' requested here impl(std::forward&lt;F&gt;(f), std::forward&lt;As&gt;(as)..., std::forward&lt;Bs&gt;(bs)..., std::forward&lt;A&gt;(a)); ^ multiple_parameter_packs.cpp:31:3: note: in instantiation of member function 'two_impl&lt;Test, std::tuple&lt;int, float, double&gt;, std::tuple&lt;&gt; &gt;::operator()' requested here impl(std::forward&lt;F&gt;(f), std::forward&lt;Ts&gt;(ts)...); ^ multiple_parameter_packs.cpp:41:3: note: in instantiation of function template specialization 'two&lt;Test, int, float, double&gt;' requested here two(Test(), 1, 1.5f, 2.1); ^ 1 error generated. Compilation exited abnormally with code 1 at Fri Mar 23 14:25:14 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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