Note that there are some explanatory texts on larger screens.

plurals
  1. POStrange behaviour of the following template code
    text
    copied!<p>In the code below, when the signified code is commented out, code works as expected - <code>Type</code> matches the (first) template argument. </p> <p>However, if I uncomment it, <code>Type</code> becomes <code>char</code> instead of <code>std::string</code>. This is the same with both MSVC and GCC. So it works when I have specialization of <code>StripTag</code> for a tag template with one and two arguments, but when I specialize it in exactly the same way for three arguments, I get this strange behavior.</p> <p>Anyone has any ideas?</p> <p>Code follows:</p> <pre><code>#include &lt;typeinfo&gt; #include &lt;stdio.h&gt; #include &lt;string&gt; template &lt;typename T&gt; struct StripTag {typedef T Type;}; template&lt;typename T, template&lt;typename T&gt; class Tag &gt; struct StripTag&lt;Tag&lt;T&gt; &gt; { typedef typename StripTag&lt;T&gt;::Type Type; }; template&lt;typename T, typename X, template&lt;typename T, typename X&gt; class Tag &gt; struct StripTag&lt;Tag&lt;T,X&gt; &gt; { typedef typename StripTag&lt;T&gt;::Type Type; }; /* //UNCOMMENT THIS AND RECOMPILE template&lt;typename T, typename X, typename Y, template&lt;typename T, typename X, typename Y&gt; class Tag &gt; struct StripTag&lt;Tag&lt;T,X,Y&gt; &gt; { typedef typename StripTag&lt;T&gt;::Type Type; }; */ template &lt;class C&gt; struct Test { typedef C Type; }; template &lt;typename A, typename B&gt; struct Blah{}; int main() { printf("typeid of StripTag=\t%s\n", typeid(StripTag&lt;std::string&gt;::Type).name()); printf("typeid of StripTag2=\t%s\n", typeid(StripTag&lt;Blah&lt;std::string, bool&gt; &gt;::Type).name()); printf("typeid of Test=\t\t%s\n", typeid(Test&lt;std::string&gt;::Type).name()); printf("typeid of std::string=\t%s\n", typeid(std::string).name()); } </code></pre>
 

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