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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:35:39+00:00 2026-06-03T02:35:39+00:00

I am writing some macros that take a function name and do some actions,

  • 0

I am writing some macros that take a function name and do some actions, one of which is getting its signature through decltype and use it as a template parameter.

I want to extend these macros to support overloaded functions. My idea is to make them take an additional argument specifying the arguments list but not the complete signature, since two function overloads cannot be different for only the return type. The problem arises when I attempt to rebuild the complete signature of the function as I did in the non-overloaded case with decltype: how do I guess the return type?

I’ve tried with result_of, but with no luck:

#include <type_traits>
#include <typeinfo>
#include <iostream>
using namespace std;

double f(int, int);
int f(int, int, int);

int main(){
    cout<<typeid(result_of<decltype(&f)(int,int, int)>::type).name()<<endl;
}

The snippet works if double f(int, int) is commented out. I understand that this is because within decltype it is unknown what of the two overloads to pick. Normally, one would prepend a dummy cast to a signature matching the desired overload, but that would mean that you know ahead the return type, hence all this stuff would be useless.

Is there a way to solve this problem, or do I have to enforce the user to specify the full signature in the macro?

EDIT:
Basically, I have these two macros:

//add a member function as a method
#define addmethod2(stringname, methodname)      fields[#stringname]=method_helper<decltype(&hold_type::methodname), &hold_type::methodname>::worker
#define addmethod(methodname)                   addmethod2(methodname, methodname)

I want to add a third, addmethod3, which takes only the arguments list (if it was the complete signature with return type, it would be trivial), in order to select the correct member function overload.

  • 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-03T02:35:40+00:00Added an answer on June 3, 2026 at 2:35 am

    What about

    template<typename T>
    struct identity { typedef T type; };
    
    template<typename T>
    using NoDeduce = typename identity<T>::type;
    
    template<typename T>
    using Identity = T;
    
    template<typename ...P, typename R>
    Identity<R(P...)> *get_f(R f(NoDeduce<P>...)) {
      return f;
    }
    

    Then you can say

    auto *f1 = get_f<int, int, int>(f);
    auto *f2 = get_f<int, int>(f);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing some macros for an excel worksheet that will add points to a
I'm writing some test cases, and I've got a test case that is using
I'm writing some code (just for fun so far) in Python that will store
I'm writing some python code to interact with a C DLL that uses structures
I am porting some PowerPoint VBA macros into C# inside a VSTO add-on which
I am writing a program that will call a function from an external library,
I've been writing some simple test cases for one of my assignments, and have
I'm writing some unit tests which are going to verify our handling of various
I am writing a macro for Visual studio that will generate some code. I
While writing some C code, I decided to compile it to assembly and read

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.