Lambda and bind do not work together in VS2010

This code cannot compile under VS2010:

#include <functional>

using namespace std;

void test()
{
    auto f = [] (int) {};
    bind(f, 10);
}

It gives a long error pointing to the insides of the implementation bind. If I switch to a normal function instead of a lambda, it bindworks fine, so I think this is a bug in VS2010, but maybe I missed something. Can you help me?

+3
source share
1 answer

It seems that VC10 cannot handle lambdas as arguments std::bind. It seems to be expecting either a function pointer or a function object. I don't know if this is a mistake, but I suspect that it is, since the lambda function should become objects of the function at compile time.

Anyway, if you need a workaround, this compiles for me:

std::function<void(int)> func = [] (int) {};
std::bind(func, 10);
+4
source

Source: https://habr.com/ru/post/1793555/


All Articles