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 554279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:41:34+00:00 2026-05-13T11:41:34+00:00

While doing variadic template programming in C++11 on GCC, once in a while I

  • 0

While doing variadic template programming in C++11 on GCC, once in a while I get an error that says “Sorry, unimplemented: cannot expand ‘Identifier…’ into a fixed-length arugment list.” If I remove the “…” in the code then I get a different error: “error: parameter packs not expanded with ‘…'”.

So if I have the “…” in, GCC calls that an error, and if I take the “…” out, GCC calls that an error too.

The only way I have been able to deal with this is to completely rewrite the template metaprogram from scratch using a different approach, and (with luck) I eventually come up with code that doesn’t cause the error. But I would really like to know what I was doing wrong. Despite Googling for it and despite much experimentation, I can’t pin down what it is that I’m doing differently between variadic template code that does produce this error, and code that does not have the error.

The wording of the error message seems to imply that the code should work according the C++11 standard, but that GCC doesn’t support it yet. Or perhaps it is a compiler bug?

Here’s some code that produces the error. Note: I don’t need you to write a correct implementation for me, but rather just to point out what is about my code that is causing this specific error

// Used as a container for a set of types.
template <typename... Types> struct TypePack
{
    // Given a TypePack<T1, T2, T3> and T=T4, returns TypePack<T1, T2, T3, T4>
    template <typename T>
    struct Add
    {
        typedef TypePack<Types..., T> type;
    };
};

// Takes the set (First, Others...) and, while N > 0, adds (First) to TPack.
// TPack is a TypePack containing between 0 and N-1 types.
template <int N, typename TPack, typename First, typename... Others>
struct TypePackFirstN
{
    // sorry, unimplemented: cannot expand ‘Others ...’ into a fixed-length argument list
    typedef typename TypePackFirstN<N-1, typename TPack::template Add<First>::type, Others...>::type type;
};

// The stop condition for TypePackFirstN:  when N is 0, return the TypePack that has been built up.
template <typename TPack, typename... Others>
struct TypePackFirstN<0, TPack, Others...> //sorry, unimplemented: cannot expand ‘Others ...’ into a fixed-length argument list
{
    typedef TPack type;
};

EDIT: I’ve noticed that while a partial template instantiation that looks like does incur the error:

template <typename... T>
struct SomeStruct<1, 2, 3, T...> {};

Rewriting it as this does not produce an error:

template <typename... T>
struct SomeStruct<1, 2, 3, TypePack<T...>> {};

It seems that you can declare parameters to partial specializations to be variadic; i.e. this line is OK:

template <typename... T>

But you cannot actually use those parameter packs in the specialization, i.e. this part is not OK:

SomeStruct<1, 2, 3, T...>

The fact that you can make it work if you wrap the pack in some other type, i.e. like this:

SomeStruct<1, 2, 3, TypePack<T...>>

to me implies that the declaration of the variadic parameter to a partial template specialization was successful, and you just can’t use it directly. Can anyone confirm this?

  • 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-13T11:41:35+00:00Added an answer on May 13, 2026 at 11:41 am

    There is a trick to get this to work with gcc. The feature isn’t fully implemented yet, but you can structure the code to avoid the unimplemented sections. Manually expanding a variadic template into a parameter list won’t work. But template specialization can do that for you.

    template< char head, char ... rest >
    struct head_broken
    {
       static const char value = head;
    };
    
    template< char ... all >
    struct head_works; // make the compiler hapy
    
    template< char head, char ... rest >
    struct head_works<head,rest...> // specialization
    {
       static const char value = head;
    };
    
    template<char ... all >
    struct do_head
    {
       static const char head = head_works<all...>::value;
       //Sorry, unimplemented: cannot expand 'all...' into a fixed-length arugment list
       //static const char head = head_broken<all...>::value;
    };
    
    int main
    {
       std::cout << head_works<'a','b','c','d'>::value << std::endl;
       std::cout << head_broken<'a','b','c','d'>::value << std::endl;
       std::cout << do_head<'a','b','c','d'>::head << std::endl;
    }
    

    I tested this with gcc 4.4.1

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

Sidebar

Ask A Question

Stats

  • Questions 516k
  • Answers 516k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Setting the IsNull and IsNullSpecified properties is absolutely fine. For… May 16, 2026 at 6:45 pm
  • Editorial Team
    Editorial Team added an answer with doesn't really replace try/except, but, rather, try/finally. Still, you… May 16, 2026 at 6:45 pm
  • Editorial Team
    Editorial Team added an answer Use a javascript setTimeout(). setTimeout(function() { $("#main_content").load("/pre_config/function.php?type="+type+"piz&count=1", successCallback ); },… May 16, 2026 at 6:45 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

While doing some refactoring I've found that I'm quite often using a pair or
While doing some JavaScript performance tests I came up with the following piece of
While doing some random experimentation with a factorial program in C, Python and Scheme.
While doing performance testing on windows, i usually use perfmon. But when i put
while doing adhoc testing tester got the crash with the crash report : Exception
While doing Windows Mobile development, which language should I use? C# or C++ or
While doing some small regex task I came upon this problem. I have a
while doing some homework in my very strange C++ book, which I've been told
while doing flex project iam unable to start my Jboss server. can any one
While doing filing im stuck here.The condition of the while loop is not working.The

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.