Access template's arguments with partial type knowledge
<p>I have some code with deep C++ 11 variadic template's magic usage. I am using specialized classes to identify parts of template tree, which I am naming "tags". Each tag has unique number identifier.
I need to find a way how to access tag's identifiers</p>

<p>Here is some small example:</p>

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

template &lt;unsigned long ID, typename PARAM&gt;
class tag_
{
    //getter for ID. Better to exclude it. If possible - move to external helper
    constexpr static unsigned long get_id() {return ID;}
    //PARAM is used in some functions of this class
};

//tag's declarations for future usage
template&lt;typename PARAM&gt;
using tag1 = tag_&lt;1UL, PARAM&gt;;
template&lt;typename PARAM&gt;
using tag2 = tag_&lt;2UL, PARAM&gt;;
template&lt;typename PARAM&gt;
using tag3 = tag_&lt;3UL, PARAM&gt;;

//helper class that can iterate TAGS
template &lt;template&lt;typename&gt; class... TAGS&gt;
struct helper
{};
template &lt;template&lt;typename&gt; class TAG&gt;
struct helper&lt;TAG&gt;
{
    static void print_tag(std::ostream&amp; out)
    {
        out &lt;&lt; std::string("Tag");
        out &lt;&lt; TAG::get_id();  // Here I can't call: error: 'template&lt;class&gt; class TAG' used without template parameters
    }
};
template &lt;template&lt;typename&gt; class TAG, template&lt;typename&gt; class... TAGS&gt;
struct helper&lt;TAG, TAGS...&gt;
{
    static void print_tag(std::ostream&amp; out)
    {
        out &lt;&lt; std::string("Tag");
        out &lt;&lt; TAG::get_id();  // Here I can't call: error: 'template&lt;class&gt; class TAG' used without template parameters
        out &lt;&lt; std::string(", ");
        helper&lt;TAGS...&gt;::print_tag(out);
    }
};

//this class uses tags for some processing
template &lt;template&lt;typename&gt; class... TAG_LIST&gt;
class tagged
{
public:
    void test1(std::ostream&amp; out)
    {
        out &lt;&lt; std::string("This function works good");
    }
    void test2(std::ostream&amp; out)
    {
        helper&lt;TAG_LIST...&gt;::print_tag(out);
    }
};

// this class is re-defined for some types of T
template&lt;typename T, typename PARAM&gt;
class usage
{
public:
    void test1(std::ostream&amp; out)
    {
        details.test1(out);
    }
    void test2(std::ostream&amp; out)
    {
        details.test2(out);
    }

    T details;
    PARAM params;
};

//endpoint
struct finish{};

//definition for future usage
template&lt;template&lt;typename&gt; class T1, template&lt;typename&gt; class T2, template&lt;typename&gt; class T3, typename PARAM&gt;
using multitag = usage&lt;tagged&lt;T1, T2, T3&gt;, PARAM&gt;;

int main(int argc, const char* argv[])
{
    // this way I am construction my objects tree
    multitag&lt;tag1, tag2, tag3, tag1&lt;tag2&lt;tag3&lt;finish&gt;&gt;&gt;&gt; tmp;
    tmp.test1(std::cout); // ok
    std::cout &lt;&lt; std::endl;
    tmp.test2(std::cout);  //compile error. I want to get "Tag1, Tag2, Tag3" printed
    std::cout &lt;&lt; std::endl;
}
</code></pre>