Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>This is a self answer I came up with as a variant of the answer from Kerrek SB</strong></p> <p>It is possible to make a trait that extracts <code>std::vector</code> from <code>std::vector&lt;int&gt;</code> and exposes it as <code>::type</code> via a trait. Yes, this solution is nearly identical to Kerrek's, but to me the use syntax is more aesthetic, putting the template parameters after <code>::type</code>.</p> <pre><code>template &lt;typename T, typename ...&gt; struct retemplate { typedef T type; }; template &lt;template &lt;typename ...&gt; class Tmpl, typename ...T&gt; struct retemplate&lt;Tmpl&lt;T...&gt;&gt; { template &lt;typename ...AR&gt; using type=Tmpl&lt;AR...&gt; ; }; </code></pre> <p>with this you actually get <code>retemplate&lt;T&lt;A,B,C&gt;&gt;::type</code> equal to the template <code>T</code></p> <p>example use:</p> <pre><code>typedef std::vector&lt;int&gt; intvec; typedef retemplate&lt;intvec&gt;::type&lt;double&gt; doublevec; </code></pre> <p>or to expose the container type </p> <pre><code>typedef std::vector&lt;int&gt; intv; template &lt;typename ...T&gt; using vector_T= retemplate&lt;intv&gt;::type&lt;T...&gt; ; </code></pre> <p>Note that when using this in template context, an extra <code>template</code> is required just after <code>::</code>, like this: (elaborating on the comment from Xeo)</p> <pre><code>template &lt;typename T&gt; typename retemplate&lt;T&gt;::template type&lt;double&gt; containedDouble(T&amp; a) { decltype(containedDouble(a)) out; for (auto &amp;i : a) out.push_back(i); return out; } </code></pre> <p>What that does is to take an object of type <code>T1&lt;T2&gt;</code> and copy its content into a <code>T1&lt;double&gt;</code>. For example with <code>T1==std::vector</code> and <code>T2==int</code>. </p>
    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.
    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