Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8840299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:26:04+00:00 2026-06-14T10:26:04+00:00

I have a problem with variadic template templates: template <typename T> class A {

  • 0

I have a problem with variadic template templates:

            template <typename T> class A { };
            template< template <typename> class T> class B { };
            template <template <typename> class T, typename parm> class C { typedef T<parm> type; };
            template <typename... types> class D { };
            template <template <typename...> class T, typename ... parms> class E { typedef T<parms...> type; };

            // How to pass list in list??
            template < template <typename...> class ...T, ???>
            class F
            {
            };

First, pass a type to the template, no problem:

            A<int> a; //ok

Now, I want to create an instance from B, but no way to pass the template template param:

            B<A> b; // ok, but no chance to submit <int> inside A!

So I have to extend the parameter list:

            C<A, int> c; // ok, this transport int as parm into A

Now I play with variadic templates in standard fashion:

            D<> d1; // ok
            D<int, float, double> d2;   //ok

Passing parameters into the variadic part is also strait forward:

            E<D> e1;    //ok
            E<D, double, float, int> e2; //ok

BUT: If I want to have a list of lists, I find no syntax which will me enable to pass
parameter lists to the list of types. What my intend is something like this. but also the above example shows that B<A<int>> b; is an error! So the following example couldn’t work 🙁

            F< D< int, float>, D< int>, D <float, float, float> > f;

My target is to unroll the list of lists via template specialization. Any hints?

My solution after I understood the problem. Thanks!

Now I can unroll my variadic variadic template template as in the following example. The simple problem was, that I wait for a template class and not for a simple type. Sometimes, the solution can be so easy 🙂

Thats my working result now:

    template <typename ... > class D;

    template <typename Head, typename... types>
    class D<Head, types...>
    {
       public:
          static void Do() { cout << "AnyType" << endl; D<types...>::Do(); }
    };

    template<>
    class D<>
    {
       public:
          static void Do() { cout << "End of D" << endl; }
    };

    template < typename ...T> class H;

    template < typename Head, typename ...T>
    class H<Head, T...>
    {
       public:
          static void Do()
          {
             cout << "unroll H" << endl;
             cout << "Subtype " << endl;
             Head::Do();
             H<T...>::Do();
          }
    };

    template <>
    class H<>
    {
       public:
          static void Do() { cout << "End of H" << endl; }
    };


    int main()
    {
       H< D<int,int,int>, D<float, double, int> >::Do();
       return 0;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T10:26:06+00:00Added an answer on June 14, 2026 at 10:26 am

    You can unpack one variadic specialisation at a time through specialisation:

    template<typename...> struct S;
    template<> struct S<> { constexpr static int n = 0; };
    template<template<typename...> class T, typename... Us, typename... Vs>
    struct S<T<Us...>, Vs...> {
        constexpr static int n = sizeof...(Us) + S<Vs...>::n;
    };
    
    template<typename...> struct D {};
    
    #include <iostream>
    int main() {
        std::cout << S<D<int, int, int>, D<int, int>, D<int>>::n << '\n'; // prints 6
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem in C#. I have a list box and a class called
I have the following problem: Suppose I have some basic counter class Counter .
I have problem with consuming DbContext class in EF 4.3 CodeFirst approach. As for
i have problem to pass data from view to controller , i have view
I have problem with List<Image> List<Image> _Images = new List<Image>(); int currIndex = 0;
Continuing my journey into the world of variadic templates , I encountered another problem.
I have a class template and I can't seem to figure out how to
I have problem with ActionLink. I'd like to pass to my ActionLink parameter for
Using variadic template arguments together with a simple template argument I have experienced some
I have no problem passing the address of a function template specialization to a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.