Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lambda and bind not working together in VS2010

This code fails to compile under VS2010:

#include <functional>

using namespace std;

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

It gives a long error pointing to the internals of bind implementation. If I switch to a normal function instead of a lambda, the bind works fine, so I believe this is a bug in VS2010 but maybe I'm missing something. Can you help me?

like image 927
Loghorn Avatar asked May 06 '26 20:05

Loghorn


1 Answers

It seems VC10 cannot cope with lambdas as arguments to std::bind. It seems to expect either a function pointer or a function object. I don't know whether this is a bug, but I suspect it is, since lambda function should become function objects during compilation.

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

std::function<void(int)> func = [] (int) {};
std::bind(func, 10);
like image 161
sbi Avatar answered May 08 '26 10:05

sbi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!