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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:38:51+00:00 2026-06-15T08:38:51+00:00

I have a pretty exotic problem, since I am trying to create some sort

  • 0

I have a pretty exotic problem, since I am trying to create some sort of a compiler…
I want to pass a lambda expression to a templated function like this:

    template<class T>
delegate<T>* bind(std::function<T> func)
{
    return nullptr;
}

So that I can now call

bind([&](int a) { // do something });

… So normally, this wouldn’t be a problem, since std::function is able to capture a lambda. But here the problem is that (let’s assume) I don’t know or don’t want to provide the info about what “T” is exactly. It could be any function signature you could also insert into std::function<>…

I also need to pass this “inferred” signature back to the “delegate” class I want to return and that delegate class needs to be a pointer to class…

For now I have come up with this:

template<class T>
struct delegate : public std::function<T>
{
    delegate(const std::function<T>& func) : std::function<T>(func) { }
    delegate(const delegate<T>& func) { }
};

template<class T>
delegate<T>* bind(std::function<T>&& func)
{
    return new delegate<T>(std::forward<std::function<T>>(func));
}

But the above example of a call to “bind” fails with “failed template argument deduction”. How can I get this to work without having to specify the “T” parameter explicitly when calling “bind” (then it works, at least)?

Since in theory my compiler has all the info to workaround this issue, I could just insert the instance of “T”, but this would make the generated code unnecessarily convoluted.

BTW, I am using the lastest Clang compiler.


Here is the final solution:

    template<typename T> struct get_signature;
template<typename Mem, typename Ret, typename... Args> struct get_signature<Ret(Mem::*)(Args...) const> {
    typedef Ret type(Args...);
};

template<class T> 
delegate<typename get_signature<decltype(&T::operator())>::type>* bind(T func)
{
    return nullptr;
}

Be aware that you may need to adjust the “const” modifiers to your needs.

  • 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-15T08:38:52+00:00Added an answer on June 15, 2026 at 8:38 am

    First, you have completely screwed up your rvalue references. Your forwarding does not work at all.

    Secondly, that’s impossible in some cases.. For some function objects, you could infer the signature by taking the member function pointer to operator() and inspecting it’s signature. But for others, they will be overloaded and it will not work.

    template<typename T> struct get_signature;
    template<typename Mem, typename Ret, typename... Args> 
    struct get_signature<Ret(Mem::*)(Args...)> {
        typedef Ret(Args...) type;
    };
    
    template<class T> 
    delegate<typename get_signature<&T::operator()>::type>* bind(T func)
    {
        return nullptr;
    }
    

    Thirdly, std::bind?

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

Sidebar

Related Questions

I have a pretty simple trigger: CREATE OR REPLACE FUNCTION f_log_datei() RETURNS TRIGGER AS
I have a pretty large object that I need to pass to a function
I want to make some static constants globally visible. I'm pretty familiar how to
I have pretty big table with lots of columns. I want to find all
What I'm trying to do: have pretty URLs in the format ' http://domain.tld/one/two/three ',
I have pretty big background of .net, and I've decided that i want to
I want to have pretty and SEO oriented URLs in my site. I've build
I'm trying to print image from Silverlight application. I have pretty good quality scans
I'm looking to find some way to have pretty print of curl's output in
I have pretty much tried everything but still have this same problem. I have

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.