lambda in std::bind, msvc 2010

Unfortunately, msvc2010 doesn’t support lambdas as parameter for std::bind. For example,

you cannot write something like this:

std::bind([](int x){ return x; },42)();

The problem is that bind powered by result_of, and vc10 uses old way to handle result of the expression.

In vc11 it is fixed. Internally result_of uses decltype.

As always, you can write functor instead of lambda and pass it to bind function:
class T
{
public:
int operator()(int x)
{
return x;
}
};

T f;
std::bind(f,42);

Advertisements