Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>One way to do it is to recursively pass two tuples to a helper struct that takes the first element of the "source" tuple and adds it to the end of the another one:</p> <pre><code>#include &lt;iostream&gt; #include &lt;tuple&gt; #include &lt;type_traits&gt; namespace detail { template&lt;typename...&gt; struct truncate; // this specialization does the majority of the work template&lt;typename... Head, typename T, typename... Tail&gt; struct truncate&lt; std::tuple&lt;Head...&gt;, std::tuple&lt;T, Tail...&gt; &gt; { typedef typename truncate&lt; std::tuple&lt;Head..., T&gt;, std::tuple&lt;Tail...&gt; &gt;::type type; }; // this one stops the recursion when there's only // one element left in the source tuple template&lt;typename... Head, typename T&gt; struct truncate&lt; std::tuple&lt;Head...&gt;, std::tuple&lt;T&gt; &gt; { typedef std::tuple&lt;Head...&gt; type; }; } template&lt;typename...&gt; struct tuple_truncate; template&lt;typename... Args&gt; struct tuple_truncate&lt;std::tuple&lt;Args...&gt;&gt; { // initiate the recursion - we start with an empty tuple, // with the source tuple on the right typedef typename detail::truncate&lt; std::tuple&lt;&gt;, std::tuple&lt;Args...&gt; &gt;::type type; }; int main() { typedef typename tuple_truncate&lt; std::tuple&lt;bool, double, int&gt; &gt;::type X; // test std::cout &lt;&lt; std::is_same&lt;X, std::tuple&lt;bool, double&gt;&gt;::value; // 1, yay } </code></pre> <p><a href="http://coliru.stacked-crooked.com/view?id=7796365537a3d762fde9b92aabb117ef-3725be9f9ce62f113fc473b4ae69c419" rel="nofollow">Live example</a>.</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. This table or related slice is empty.
    1. VO
      singulars
      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