Suppose I have a type:
struct my_type
{
double operator()(int a)
{
return 3.1415;
}
};
Then I would like to wrap it in std::function. Consider two different approaches:
my_type m_t;
std::function<double(int)> f(std::move(m_t));
std::cout << f(4) << std::endl;
Everything works well, as I expected, the first digits of PI are printed. Then the second approach:
std::function<double(int)> ff(my_type());
std::cout << ff(4) << std::endl;
It seems to me that this code absolutely matches the first. rvaluepassed as an argument to the wrapper function. But the problem is that the second code does not compile! I really don’t know why.
source
share