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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:55:26+00:00 2026-05-24T19:55:26+00:00

This is related to my earlier post . I’d like to know why one

  • 0

This is related to my earlier post. I’d like to know why one attempted solution didn’t work.

template <typename... T>             /* A */
size_t num_args ();

template <>
size_t num_args <> ()
{
    return 0;
}

template <typename H, typename... T> /* B */
size_t num_args ()
{
    return 1 + num_args <T...> ();
}

If I try to call, say, num_args<int,float>() then the error is that the function call is ambiguous:

  • A with T={int,float}
  • B with H=int, T={float}

I don’t understand how this is ambiguous — A is a declaration and B is a definition of the function declared by A. Right?

I’m trying to make this example work and the responses to my earlier question seem to claim that it can never work.

If that’s the case, what’s the point of variadic free functions? What can they do?

  • 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-24T19:55:27+00:00Added an answer on May 24, 2026 at 7:55 pm

    I don’t understand how this is ambiguous — A is a declaration and B
    is a definition of the function declared by A. Right?

    No. A is a declaration of a function template, and B is a declaration (and definition) of another function template.

    The compiler has no way to decide between the two: they both have no arguments, and the template arguments are a match for both.

    The one in the middle is an explicit total specialization of the function template declared in A.

    If you tried to make B another specialization of A:

    template <typename H, typename... T> /* B */
    size_t num_args<H, T...>()
    {
        return 1 + num_args <T...> ();
    }
    

    … you’d end up with a partial specialization of a function template, which is not allowed.

    You can do this with the usual trick of using a class template with partial specializations and a function template that calls into the class template:

    template <typename... T>
    class Num_Args;
    
    template <>
    struct Num_Args <>
    {
        static constexpr size_t calculate() {
            return 0;
        }
    };
    
    template <typename H, typename... T>
    struct Num_Args <H, T...>
    {
        static constexpr size_t calculate() {
            return 1 + Num_Args<T...>::calculate();
        }
    };
    
    template <typename... T> /* B */
    constexpr size_t num_args ()
    {
        return Num_Args<T...>::calculate();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is related with one of my earlier questions.. Previous Post In there
This query is somewhat related to this earlier one on sorting where, it was
This is a related question to one I posted earlier... I'm trying to sum
This is a related question to one I posted earlier today, I was initially
This question is related to one I asked earlier: Adding buttons to a TabControl
This Question is Related to my earlier post here: CSS loading issue with Android
This is related to an earlier question by a different user, asking How to
This is related to my earlier question. ren C:\Temp\%%A %%A if errorlevel 0 (
This is related to this question I asked earlier about syntax highlighting user-defined blocks
I know I asked a related question earlier. I just had another thought. using

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.