Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm not entirely sure what you are asking about. I thought the sample you gave was interesting and played a little bit with it.</p> <p>I came up with an implementation that makes <code>span&lt;a,b&gt;</code> to be a <em>template alias</em> for <code>indexes&lt;a, ..., b&gt;</code>, using the trick of type deduction in <code>constexpr</code> functions:</p> <pre><code>template &lt;int a, int b&gt; using span = decltype(expand_span&lt;a,b&gt;()); </code></pre> <p>Now you can have your cake and eat it:</p> <pre><code>//////////////////////////////////////////////////////////////// // using indirect template arguments template&lt;typename&gt; struct indirect_work { }; void test_indirect() { indirect_work&lt;indexes&lt;1,2,3,4&gt;&gt; x; indirect_work&lt;span&lt;1,4&gt;&gt; y; x = y; // x and y are of identical types static_assert(std::is_same&lt;indexes&lt;1,2,3,4&gt;, span&lt;1,4&gt;&gt;::value, "fact check"); } </code></pre> <p>But, perhaps more interestingly, <strong>you can still have your primary <code>work</code> template take a raw <code>&lt;int...&gt;</code></strong> template argument list: </p> <pre><code>//////////////////////////////////////////////////////////////// // using direct template arguments template&lt;int...&gt; struct direct_work { }; // deduction alias: template&lt;int... direct&gt; constexpr direct_work&lt;direct...&gt; deduction_helper(indexes&lt;direct...&gt;); template &lt;typename Idx&gt; using deduce = decltype(deduction_helper(Idx{})); void test_direct() { direct_work&lt;1,2,3,4&gt; x; deduce&lt;indexes&lt;1,2,3,4&gt;&gt; y; deduce&lt;span&lt;1,4&gt;&gt; z; static_assert(std::is_same&lt;decltype(x), decltype(y)&gt;::value, "fact check"); static_assert(std::is_same&lt;decltype(x), decltype(z)&gt;::value, "fact check"); } </code></pre> <p>See a complete working demonstration here: <a href="http://ideone.com/U2geNF" rel="noreferrer">gcc on ideone</a>. I compiled it with clang locally.</p> <hr> <h3>Full code</h3> <p>Code for <code>expand_span</code> duplicated here in case link should go dead:</p> <pre><code>#include &lt;type_traits&gt; template &lt;int...&gt; struct indexes {}; namespace { template&lt;int a, int... other&gt; constexpr indexes&lt;a, other...&gt; combine(indexes&lt;other...&gt; deduce); template&lt;int a, int b, typename Enable = void&gt; struct expand_span_; // primary template&lt;int a, int b&gt; struct expand_span_&lt;a, b, typename std::enable_if&lt; (a==b), void &gt;::type&gt; { static constexpr indexes&lt;a&gt; dispatch(); }; template&lt;int a, int b&gt; struct expand_span_&lt;a, b, typename std::enable_if&lt; (a&lt;b), void &gt;::type&gt; { static constexpr decltype(combine&lt;a&gt;(expand_span_&lt;a+1, b&gt;::dispatch())) dispatch(); }; template&lt;int a, int b&gt; constexpr auto expand_span() -&gt; decltype(expand_span_&lt;a,b&gt;::dispatch()); } template &lt;int a, int b&gt; using span = decltype(expand_span&lt;a,b&gt;()); //////////////////////////////////////////////////////////////// // using indirect template arguments template&lt;typename&gt; struct indirect_work { }; void test_indirect() { indirect_work&lt;indexes&lt;1,2,3,4&gt;&gt; x; indirect_work&lt;span&lt;1,4&gt;&gt; y; x = y; // x and y are of identical types static_assert(std::is_same&lt;indexes&lt;1,2,3,4&gt;, span&lt;1,4&gt;&gt;::value, "fact check"); } //////////////////////////////////////////////////////////////// // using direct template arguments template&lt;int...&gt; struct direct_work { }; // deduction alias: template&lt;int... direct&gt; constexpr direct_work&lt;direct...&gt; deduction_helper(indexes&lt;direct...&gt;); template &lt;typename Idx&gt; using deduce = decltype(deduction_helper(Idx{})); void test_direct() { direct_work&lt;1,2,3,4&gt; x; deduce&lt;indexes&lt;1,2,3,4&gt;&gt; y; deduce&lt;span&lt;1,4&gt;&gt; z; static_assert(std::is_same&lt;decltype(x), decltype(y)&gt;::value, "fact check"); static_assert(std::is_same&lt;decltype(x), decltype(z)&gt;::value, "fact check"); } int main() { test_indirect(); test_direct(); } </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.
    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