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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:41:10+00:00 2026-05-24T20:41:10+00:00

I would like to return a std::function whose type is dependent on the type

  • 0

I would like to return a std::function whose type is dependent on the type of one template argument of my function template.

// Return a function object whose type is directly dependent on F
template<typename F, typename Arg1, typename Arg2>
auto make_f2_call(Arg1&& arg1, Arg2&& arg2)
    -> std::function<--what-goes-here?-->
{
    return [arg1, arg2](F f) { return f(arg1, arg2); };
}

// Usage example, so that it's clearer what the function does:
...
typedef bool (*MyFPtrT)(long id, std::string const& name);
bool testfn1(long id, std::string const& name);
...
auto c2 = make_f2_call<MyFPtrT>(i, n); // std::function<bool(F)>
...
bool result = c2(&testfn1);

Logically --what-goes-here?-- should be the function signature of a function returning the return type of F and taking an argument of type F but I seem to be unable to tell my compiler (Visual Studio 2010 Express) this intent. (Take Note: In the usage example, it would be std::function<bool(F)>.)

(Note: I have tried variations of std::result_of<F>::type without success.)

Is this possible with C++0x?

  • 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-24T20:41:11+00:00Added an answer on May 24, 2026 at 8:41 pm

    The following compiles for me with both GCC 4.5.3 and MSVC 2010 EE SP1

    auto make_f2_call(Arg1&& arg1, Arg2&& arg2)
        -> std::function< typename std::result_of<F(Arg1, Arg2)>::type (F)>
    {
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to pass a function as a template argument to another function
I would like to return the id of a newly created object for my
I have a method where I would like to return an object instance of
I am using matplotlib in a django app and would like to directly return
I would like to return a string with all of the contents of a
I would like to return an array of string in my web services I've
I have a script with a factory method that I would like to return
Given the following XML, I would like to return all eventtitles where the eventtype
Given the following directory: string fullpath = C:\MyDir1\MyDir2\MyDir3; I would like to return MyDir3
I'm constructing a regex that is looking for dates. I would like to return

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.