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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:48:33+00:00 2026-05-27T18:48:33+00:00

In C++0x, we use use std::function like the following: int normal_function() { return 42;

  • 0

In C++0x, we use use std::function like the following:

int normal_function() {
    return 42;
}
std::function<int()> f = normal_function;

So to get an std::function instance, we have to define its type firstly. But it’s boring and sometimes hard.

So, can we just use make to get a std::function instance just like std::tuple?

In fact, I just googled, C++0x doesn’t provide such make facility.

Why C++0x no provide make facility?
Can we implement it?

  • 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-27T18:48:34+00:00Added an answer on May 27, 2026 at 6:48 pm

    Yes we can implement it

    template<typename T>
    std::function<T> make_function(T *t) {
      return { t };
    }
    

    This requires that you pass a function to make_function. To prevent overload to pick this up for something other than a plain function, you can SFINAE it

    template<typename T>
    std::function<
      typename std::enable_if<std::is_function<T>::value, T>::type
    > make_function(T *t) {
      return { t };
    }
    

    You cannot pass it class type function objects though and no member pointers. For arbitrary function objects there is no way to obtain a call signature (what would you do if the respective operator() is a template?). This probably is the reason that C++11 provides no such facility.

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

Sidebar

Related Questions

Suppose I have the following two data structures: std::vector<int> all_items; std::set<int> bad_items; The all_items
I use std::tr1::shared_ptr extensively throughout my application. This includes passing objects in as function
Whenever I use the rand function in C++: #include<iostream> #include<time.h> #include<stdlib.h> using namespace std;
Assume I have a class foo, and wish to use a std::map to store
I have the following code in D import std.stdio; class Thing { // Fields
i use smart pointers in the following way: typedef std::tr1::shared_ptr<RealAlgebraicNumber> RealAlgebraicNumberPtr; I'm using the
In one of my programs for school, I use the following function to count
I wanted to use boost::thread in my program, but get the following compiler error
I'd like to use the boost::transform_iterator together with boost::bind to return the result of
I have the following code which works as expected: #include <iostream> using namespace std;

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.