Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In the context of variadic template, the ellipsis <code>...</code> is used to unpack the template parameter pack if it appears on the right side of an expression (call this expression <em>pattern</em> for a moment). The rule is that whatever <em>pattern</em> is on the left side of <code>...</code> is repeated &mdash; the unpacked patterns (call them <em>expressions</em> now) are separated by comma <code>,</code>. </p> <p>It can be best understood by some examples. Suppose you have this function template:</p> <pre><code>template&lt;typename ...T&gt; void f(T ... args) { g( args... ); //pattern = args h( x(args)... ); //pattern = x(args) m( y(args...) ); //pattern = args (as argument to y()) n( z&lt;T&gt;(args)... ); //pattern = z&lt;T&gt;(args) } </code></pre> <p>Now if I call this function passing <code>T</code> as <code>{int, char, short}</code>, then each of the function call is expanded as:</p> <pre><code>g( arg0, arg1, arg2 ); h( x(arg0), x(arg1), x(arg2) ); m( y(arg0, arg1, arg2) ); n( z&lt;int&gt;(arg0), z&lt;char&gt;(arg1), z&lt;short&gt;(arg2) ); </code></pre> <p>In the code you posted, <code>std::forward</code> follows the fourth pattern illustrated by <code>n()</code> function call.</p> <p><strong>Note the difference between <code>x(args)...</code> and <code>y(args...)</code> above!</strong></p> <hr> <p>You can use <code>...</code> to initialize an array also as:</p> <pre><code>struct data_info { boost::any data; std::size_t type_size; }; std::vector&lt;data_info&gt; v{{args, sizeof(T)}...}; //pattern = {args, sizeof(T)} </code></pre> <p>which is expanded to this:</p> <pre><code>std::vector&lt;data_info&gt; v { {arg0, sizeof(int)}, {arg1, sizeof(char)}, {arg2, sizeof(short)} }; </code></pre> <hr> <p>I just realized a pattern could even include access specifier such as <code>public</code>, as shown in the following example:</p> <pre><code>template&lt;typename ... Mixins&gt; struct mixture : public Mixins ... //pattern = public Mixins { //code }; </code></pre> <p>In this example, the pattern is expanded as:</p> <pre><code>struct mixture__instantiated : public Mixin0, public Mixin1, .. public MixinN </code></pre> <p>That is, <code>mixture</code> derives <em>publicly</em> from all the base classes.</p> <p>Hope that helps.</p>
    singulars
    1. This table or related slice is empty.
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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