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

The Archive Base Latest Questions

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

This is a follow up on How do I get the argument types of

  • 0

This is a follow up on How do I get the argument types of a function pointer in a variadic template class?

I have this struct to access the arguments of a variadic template:

template<typename T> 
struct function_traits;  

template<typename R, typename ...Args> 
struct function_traits<std::function<R(Args...)>>
{
    static const size_t nargs = sizeof...(Args);

    typedef R result_type;

    template <size_t i>
    struct arg
    {
        typedef typename std::tuple_element<i, std::tuple<Args...>>::type type;
    };
};

And I access the type of an argument of Args with

typedef function<void(Args...)> fun;
std::cout << std::is_same<int, typename function_traits<fun>::template arg<0>::type>::value << std::endl;

However, I would like to iterate through the arguments to be able to handle an arbitrary number of arguments. The following doesn’t work, but to illustrate what I want:

for (int i = 0; i < typename function_traits<fun>::nargs ; i++){ 
    std::cout << std::is_same<int, typename function_traits<fun>::template arg<i>::type>::value << std::endl;
}
  • 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-28T19:54:56+00:00Added an answer on May 28, 2026 at 7:54 pm

    You’d need to do a compile-time iteration along the lines of

    template <typename fun, size_t i> struct print_helper {
        static void print() {
            print_helper<fun, i-1>::print();
            std::cout << std::is_same<int, typename function_traits<fun>::template arg<i-1>::type>::value << std::endl;
        }
    };
    
    template <typename fun> struct print_helper<fun,0> {
        static void print() {}
    };
    
    template <typename fun> void print() {
        print_helper<fun, function_traits<fun>::nargs>::print();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a follow up to this question , where I didn't get any
I try to get this following url using the downloadURL function as follows: http://www.ncbi.nlm.nih.gov/nuccore/27884304
I have a bunch of python methods that follow this pattern: def delete_session(guid): conn
Let's say I have a variadic function foo(int tmp, ...) , when calling foo
I am trying to follow this tutorial and I get the following error which
When I call this function, it seems to return a pointer instead of an
I have a function defined as follows: function Get-LatestProjects { [CmdletBinding()] Param ( [Parameter(ValueFromPipeline
I happen to have several functions which access different arguments of the program through
Update: Check out this follow-up question: Gem Update on Windows - is it broken?
I follow this rule but some of my colleagues disagree with it and argue

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.