Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In your case, the only way that I see would be to explicitly specialize <code>MyClass</code> for <code>InheritSomeTag</code>. However, the <a href="http://www.biomedcentral.com/1471-2105/9/11/abstract" rel="nofollow noreferrer">SeqAn paper</a> proposes a mechanism called “template sublassing” that does what you want – albeit with a different inheritance syntax, so the code isn't compatible with your current <code>main</code> function.</p> <pre><code>// Base class template &lt;typename TSpec = void&gt; class SomeTag { }; // Type tag, NOT part of the inheritance chain template &lt;typename TSpec = void&gt; struct InheritSomeTag { }; // Derived class, uses type tag template &lt;typename TSpec&gt; class SomeTag&lt;InheritSomeTag&lt;TSpec&gt; &gt; : public SomeTag&lt;void&gt; { }; template &lt;class T, class Tag=T&gt; struct MyClass { }; template &lt;class T, typename TSpec&gt; struct MyClass&lt;T, SomeTag&lt;TSpec&gt; &gt; { typedef int isSpecialized; }; int main() { MyClass&lt;SomeTag&lt;&gt; &gt;::isSpecialized test1; //ok MyClass&lt;SomeTag&lt;InheritSomeTag&lt;&gt; &gt; &gt;::isSpecialized test2; //ok } </code></pre> <p>This certainly looks strange and is very cumbersome but it allows a true inheritance mechanism with polymorphic functions that is executed at compile time. If you want to see this in action, have a look at some <a href="http://www.seqan.de/dddoc/html/INDEXPAGE_Demo.html" rel="nofollow noreferrer">SeqAn examples</a>.</p> <p>That being said, I believe that SeqAn is a special case and not many applications would profit from this extremely difficult syntax (deciphering SeqAn-related compiler errors is a real pain in the *ss!)</p>
 

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