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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:44:13+00:00 2026-05-28T03:44:13+00:00

The question almost does not make sense without an example. So here is what

  • 0

The question almost does not make sense without an example. So here is what I’m trying to do.

In general C++ allows the following:

template<class T, class U, T t, U u>
void func() {}

func<char, int, 'A', 10>();

But it seems like its natural variadic extension does not work.

template<class...T, T... t>
void func() {}

func<char, int, 'A', 10>(); 

Both clang and g++4.7 reject the above code. The error is shown where the instantiation is done. It appears to me that the two variadic lists should be parsed unambiguously because the first one has types and the other one has integral values only.

If the above is not meant to work, I think the following won’t work either.

template <class Ret, class... Args, Ret (*func)(Args...)>
class Foo {};

I think the Foo template is a rather useful thing to have.

  • 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-28T03:44:13+00:00Added an answer on May 28, 2026 at 3:44 am

    (Extra: Directly answering your first question, you can also turn template<class...T, T... t> void func() {} into a template-inside-a-template. This doesn’t work in g++4.6, but does in clang 3.0, hence it took me a while to find it.)

    Put a template inside a template:

    template<class ... T>
    struct func_types {
       template <T ... t>
       static void func_values() {
           // This next line is just a demonstration, and 
           // would need to be changed for other types:
           printf("%c %d\n", t...);
       }
    };
    
    int main() {
        func_types<char, int> :: func_values<'A', 10>();
    }
    

    Is a template-inside-a-template acceptable? An alternative is to use tuples with func< tuple<char,int> , make_tuple('A',10) >. I think this is doable, but you might have to roll your own tuple class (it appears that make_tuple isn’t a constexpr.

    Finally, you might be able to implement your Foo template as follows:

    template<typename Ret, typename ...Args>
    struct Foo {
            template< Ret (*func)(Args...)>
            struct Bar {
                    template<typename T...>
                    Bar(T&&... args) {
                            cout << "executing the function gives: "
                               << func(std::forward(args)...) << endl;
                    }
            };
    };
    
    int main () {
        Foo<size_t, const char*> ::  Bar<strlen> test1("hi");
        Foo<int, const char*, const char*> ::  Bar<strcmp> test2("compare","these");
    }
    

    This latter code is on ideone. To demonstrate, I implemented a constructor to forward the args to the function that’s code into the template.

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

Sidebar

Related Questions

first question here, be nice :P I am trying to make an infinite UIScrollView
I asked the almost the same question before also, but i have not yet
I have the following error message: 'System.Collections.Generic.Dictionary<int,SpoofClass>' does not contain a definition for 'biff'
I am almost too embarrassed to ask this question, but here we go... I
Seeing various locking related question and (almost) always finding the 'loop because of spurious
This is almost similar question to this one: - Dealing with timezones in PHP
When I asked this question I got almost always a definite yes you should
EDIT: There is the almost same question at Removing whitespace between HTML elements when
I am almost embarrassed to ask this question, but as a long time C
This is almost certainly a very silly question, but for some reason I'm having

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.