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

  • Home
  • SEARCH
  • 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 6686489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:10:39+00:00 2026-05-26T05:10:39+00:00

I had asked the similar question before , understood that i can make it

  • 0

I had asked the similar question before , understood that i can make it work by partially specialization. But to understand variadic templates basics i modified the code such like this.

template<typename T, typename... args>
struct counter{
static const int value= 1+ counter<args...>::value;
};

template<typename T>
struct counter<T>{
static const int value = 0;
};

error : “sorry, unimplemented: cannot expand ‘args …’ into a fixed-length argument list”

i understand this is bug and has been fixed in gcc 4.7.0

so to fix all this we have to use trick or whatever , which is partial specializing the template.

template<typename... Args> struct counter;

template<>
struct counter<> {
static const int value = 0;
};

template<typename T, typename... Args>
struct counter<T, Args...> {
static const int value = 1 + counter<Args...>::value;
};

Actual question: so I really want to know what special effect does partial specialization does here so that code works or I should ask how partial specialization resolves the issue? (why is it second version doesn’t hits the bug? ). Any explanation with motivation problem and examples will be very helpful.

  • 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-05-26T05:10:40+00:00Added an answer on May 26, 2026 at 5:10 am

    The second version avoids the bug because the primary template is declared as template<typename...>, i.e. it’s variadic. The key to the bug is in the error message: “sorry, unimplemented: cannot expand ‘args …’ into a fixed-length argument list” (emphasis mine).

    Thus counter<Args...>::value will work on that second case because counter is tailored to accept any number of arguments. However, in the first case where the primary template is declared as template<typename T, typename... args>, the compiler has to separate args into a fixed-length part (T) and a variadic part (the new args). Presumably that’s the very functionality that is not implemented in your version of GCC.

    I have no reason to believe that whatever machinery allows the <T, Args...> specialization of the second case to match the <typename...> primary template could be reused for fixed-length expansion.

    (Finally since the support of C++11 features is marked as ‘experimental’ by GCC you really can’t have any expectation as to what will work and what won’t, much less why and how. Those kind of questions can only reasonably be answered by GCC developers on their mailing-list, not us. We’re not mind readers.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had asked a question similar to this before, but I have a new
OK, I had asked a similar question before and had got an answer but
So I had asked a question similar to this, but I don't think the
This user asked a similar question but had no viable solution in the answers,
I've asked a similar question before, but I've done some more research and this
Sorry I know similar question have been asked many times before but like most
I've asked a similar question, but I've given up on the idea I had
I asked a similar question yesterday but I included some code that basically took
Various incarnations of this question have been asked here before, but I thought I'd
Ok I know I've asked a similar question, I understand how to do an

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.