What is the purpose of std::function
? As far as I understand, std::function
turns a function, functor, or lambda into a function object.
I
Consider a simple use case:
/* Unspecified */ f = [](int x, int y){ return x + y; };
f = [](int x, int y){ return x - y; };
int a = 42;
f = [&a](int x, int y){ return a * x * y; };
How would you specify /* Unspecified */
?
Furthermore,
std::queue jobs;
jobs.push_back([]{ std::cout << "Hi!\n"; });
jobs.push_back([]{ std::cout << "Bye!\n"; });
for(auto const &j: jobs) j();
What value_type
should be kept in jobs
?
Finally,
myButton.onClick(f);
What type does f
have? A template parameter? Okay, but how is it registered internally?