Class template specialization within template class
<p>Re-factoring legacy code I want to merge separate template classes/structs that are related to each other (to avoid namespace pollution).</p>

<p><code>Nested</code> (below) is a helper class for <code>MyStruct</code>, which i want to move <strong>into</strong> <code>MyStruct</code>.</p>

<p>But I cannot make this work:</p>

<pre><code>#include &lt;type_traits&gt;
#include &lt;iostream&gt;

struct YES {} ;
struct NO {};

template &lt;typename TYPE&gt;
struct MyStruct
{

    template &lt;typename TYPE_AGAIN = TYPE, typename SELECTOR = NO&gt;
    struct Nested
    {
        static void Print(void)
        {
            std::cout &lt;&lt; "MyStruct::Nested&lt;bool = false&gt;::Print()" &lt;&lt; std::endl;
        }
    };


    template &lt;&gt;
    struct Nested&lt;TYPE, typename std::enable_if&lt;std::is_integral&lt;TYPE&gt;::value, YES&gt;::type&gt;
    {
        static void Print(void)
        {
           std::cout &lt;&lt; "MyStruct::Nested&lt;bool = true&gt;::Print()" &lt;&lt; std::endl;
        }
    }; 

};
</code></pre>

<p>the compiler complains:</p>

<pre><code>g++ -O0 -g3 -Wall -c -fmessage-length=0 -std=c++11 -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../main.cpp"
In file included from ../main.cpp:8:0:
../MyStruct.h:31:12: error: explicit specialization in non-namespace scope ‘struct MyStruct&lt;TYPE&gt;’
  template &lt;&gt;
            ^
make: *** [main.o] Error 1
</code></pre>

<p>Actually it also bothers me to have to include </p>

<blockquote>
<pre><code>&lt;typename TYPE_AGAIN = TYPE&gt;
</code></pre>
</blockquote>

<p>But without, there are even more complains:</p>

<pre><code>g++ -O0 -g3 -Wall -c -fmessage-length=0 -std=c++11 -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../main.cpp"
In file included from ../main.cpp:8:0:
../MyStruct.h:31:12: error: explicit specialization in non-namespace scope ‘struct MyStruct&lt;TYPE&gt;’
  template &lt;&gt;
            ^
../MyStruct.h:32:9: error: template parameters not used in partial specialization:
  struct Nested&lt;typename std::enable_if&lt;std::is_integral&lt;TYPE&gt;::value, YES&gt;::type&gt;
     ^
../MyStruct.h:32:9: error:         ‘TYPE’
make: *** [main.o] Error 1
</code></pre>