Note that there are some explanatory texts on larger screens.

plurals
  1. POtemplate metaprogramming: (trait for?) dissecting a specified template into types T<T2,T3 N,T4, ...>
    primarykey
    data
    text
    <p>I'm trying to deduce the underlying template type <code>T</code> from a type <code>E = T&lt;T2,T3&gt;</code>. This would for example make it possible to make a template function pair_maker(const E &amp; a) which can be used with one of several similar types of containers. Rough meta code:</p> <pre><code>template &lt;typename T&gt; auto pairmaker(const E &amp; a) -&gt; PairContents&lt;E,std::string&gt;::type { ContainerPairMaker&lt;E,std::string&gt;::type output; ... some code ... return output; } </code></pre> <p><code>PairContents&lt;E,std::string&gt;</code> </p> <p>would transform the type <code>vector&lt;int&gt;</code> into <code>vector&lt;pair(int,std::string)&gt;</code> or <code>whatever&lt;T1&gt;</code> into <code>whatever&lt;pair(T1,std::string)&gt;</code>.</p> <p>Another similar example of type dissection is for std::array (or similar containers) where I like to figure out the <em>container</em> type to make a new similar array. For example for these kind of functions (this is actual working code now)</p> <pre><code>template &lt;typename T &gt; auto make_some3(const T &amp; a) -&gt; std::array&lt;typename T::value_type,10*std::tuple_size&lt;T&gt;::value&gt;{ return std::array&lt;typename T::value_type,10*std::tuple_size&lt;T&gt;::value&gt;{} ; } </code></pre> <p>This works fine but what I'm after is to make the explicit use of 'std::array' automatic. </p> <p>For std::array there's the tuple_size trait which helps, and a similar thing can be used to find the <code>type</code> for any second argument, but again I can't think of anything for finding the container type.</p> <p>To summarize: what kind of machinery (if any) can be used for cases like these. To which extent is it possible to deal with mixes of template arguments, template-template arguments, any number of arguments, and non-template arguments of unknown types.</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.
 

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