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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:31:37+00:00 2026-05-26T13:31:37+00:00

Related: Ambiguous overload accessing argument-less template functions with variadic parameters Simple variadic template function

  • 0

Related:

  • Ambiguous overload accessing argument-less template functions with variadic parameters
  • Simple variadic template function can't instantinate
  • Why is this variadic function ambiguous?

Consider this pair of variadic templates:

template<typename Dummy>
bool All(Param& c) {
    return true;
}

template<typename Dummy, Func* f, Func* ...rest>
bool All(Param& c) {
    return f(c) && All<Dummy, rest...>(c);
}

This works and compiles. However, how to write it without the first template parameter?

Sounds trivial? Well, that’s what I thought. 🙂 Let’s consider some ideas.

Idea #1:

template<Func* f, Func* ...rest>
bool All(Param& c) {
    return f(c) && All<rest...>(c);
}
template<>
bool All(Param& c) {
    return true;
}

Won’t work… When I attempted this I had specialization in mind, but on the second thought that’s not how it works.

In the original example I created two different templates of overloads, first taking 1 template parameter and second taking 2 or more. No ambiguities and no specialization involved. am I getting it right?

Idea #2:

bool All(Param& c) {
    return true;
}

template<Func* f, Func* ...rest>
bool All(Param& c) {
    return f(c) && All<rest...>(c);
}

Won’t work obviously, All<rest...> with rest... being empty won’t expand to a call to a non-template function.

Idea #3:

Let’s rebuild the solution a bit.

template<Func* f>
bool All(Param& c) {
    return f(c);
}

template<Func* f, Func* ...rest>
bool All(Param& c) {
    return f(c) && All<rest...>(c);
}

This one is a no-go, because All(c) would be ambiguous. Hence I need to have a 0-arg case and a >0-arg case… Or what about a 1-arg case and a >1-arg case?

Idea #3.5:

template<Func* f>
bool All(Param& c) {
    return f(c);
}

template<Func* f, Func* f2, Func* ...rest>
bool All(Param& c) {
    return f(c) && All<f2, rest...>(c);
}

Yup, works, but contains copypasta (simple in this case but might be bigger!), hence I’d say it’s no better than what I’ve started with. Just another workaround.

Idea #4:

Let’s try #1 but with classes instead of functions.

template<Func* f, Func* ...rest>
struct All {
    static bool func(Param& c) {
        return f(c) && All<rest...>(c);
    }
};
template<>
struct All {
    static bool func(Param& c) {
        return true;
    }
};

This looks promising since I can specialize classes. But hey, what is it?

sorry, unimplemented: cannot expand ‘rest …’ into a fixed-length argument list

Wasn’t this a GCC 4.4 thing? I’m on MinGW GCC 4.6.1 (tdm-1).


Anyway, should I think that I cannot do such an elementary thing in a straightforward way? Is it required to use the workaround with an additional dummy template parameter to accomplish this task?

Or is there a simple, correct variant to specify the zero-argument case, which would work?

  • 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-26T13:31:37+00:00Added an answer on May 26, 2026 at 1:31 pm

    In this question’s case, since template parameters are non-type,
    if we prepare a function with default template argument like the
    following, Dummy parameter can be saved:

    template<typename = void>
    bool All(Param& c) {
        return true;
    }
    
    template<Func* f, Func* ...rest>
    bool All(Param& c) {
        return f(c) && All<rest...>(c);
    }
    

    However, I’m not sure this is always applicable.
    For more general case, std::enable_if or similar dispatch might be needed
    (this will make the code a little lengthy though).

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

Sidebar

Related Questions

I'm seeing an ambiguous error in Firebug. I don't think it's particularly related to
Related to https://stackoverflow.com/questions/139944/where-can-one-find-free-software-icons-images I have a need for free weather-related icons. Specifically, I need
Related to this question , I decided to check the UDFs in my data
Related to this question: URL characters replacement in JSP with UrlRewrite I want to
Related to this question , what is the best practice for naming a mutex?
Related to: Query Windows Search from Java But this time to use OSX's spotlight
Related: see here I've got this command: exec((wget -O http://domain/file.zip && mysql -u user
Related to this question , I am wondering the algorithms (and actual code in
This question is related to this question. The following code compiles fine VC9 compiler
This is related to final interface in java . Among the discussion there was

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.