If i have a template function in C++11, is it then possible to wrap it in a std::function
?
My problem is like this:
I have a generic function (say a sum function) where the return type depends on the types of the arguments:
template <typename T>
auto sum(T const& a, T const& b) -> decltype(a+b)
{
return a + b;
}
and I want to wrap it in a std:function
for specific argument types (say int). I'm trying the following:
int main()
{
std::function<int(int,int)> intsum = std::bind(static_cast<int(*)(int,int)>(&sum), std::placeholders::_1, std::placeholders::_2);
auto mysum = intsum(2, 4);
std::cout << mysum << std::endl;
return 0;
}
But compiling the above code produces an error:
error: invalid static_cast from type ‘<unresolved overloaded function type>’ to type ‘int (*)(int, int)
Is there some way to achieve what I am trying to do?