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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:55:18+00:00 2026-06-17T01:55:18+00:00

Say I have a template declaration like this: template <class A, class B, class

  • 0

Say I have a template declaration like this:

template <class A, class B, class C = A (&)(B)>

How would I make it so that I could have a variable amount of objects of type C? Doing class C ...c = x won’t work because variadic template arguments can’t have default values. So this is what I’ve tried:

template <typename T>
struct helper;

template <typename F, typename B>
struct helper<F(B)> {
    typedef F (&type)(B);
};

template <class F, class B, typename helper<F(B)>::type ... C>
void f(C ...c) { // error

}

But up to the last part I get error messages. I don’t think I’m doing this right. What am I doing wrong here?

  • 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-17T01:55:19+00:00Added an answer on June 17, 2026 at 1:55 am
    template <typename T>
    struct helper;
    
    template <typename F, typename B>
    struct helper<F(B)> {
        typedef F (*type)(B);
    };
    
    template<class F, class B>
    void f()
    {
    }
    
    template <class F, class B, typename... C>
    void f(typename helper<F(B)>::type x, C... c)
    {
        std::cout << x(B(10)) << '\n';
        f<F,B>(c...);
    }
    
    int identity(int i) { return i; }
    int half(int i) { return i/2; }
    int square(int i) { return i * i; }
    int cube(int i) { return i * i * i; }
    
    int main()
    {
        f<int,int>(identity,half,square,cube);
    }
    

    Here’s a modified version that can deduce types:

    template<class F, class B>
    void f(F(*x)(B))
    {
        x(B());
    }
    
    template <class F, class B, typename... C>
    void f(F(*x)(B), C... c)
    {
        f(x);
        f<F,B>(c...);
    }
    
    int identity(int i) { return i; }
    int half(int i) { return i/2; }
    int square(int i) { return i * i; }
    int cube(int i) { return i * i * i; }
    int string_to_int(std::string) { return 42; }
    
    int main()
    {
        f(identity,half,square,cube);
        // f(identity,half,string_to_int);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a template like this <script id=rowTemplate type=text/x-jquery-tmpl> <tr> <a href=${
Say I have this: template<typename T, int X> class foo { public: void set(const
Say I have a template class that takes msgs from source, does something smart
Say I have a template function that accepts variable arguments and calls other functions
Let's say we have a template class Area , which has a member variable
Say I have the following template function: template <class T> void apply(const vector<complex<T> >&
Say I have an integer value that I output to a django template say
Lets say have this immutable record type: public class Record { public Record(int x,
Let's say you have a c++0x std::array member of a template class and you
Say I have a Boost Spirit grammar like this, where a parent rule passes

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.