jeudi 3 décembre 2015

Compilation fails when using std::bind with Concurrency::parallel_for

Came across a strange compilation error while migrating some old code, which made use of the boost library, to C++11. Specifically, using Visual Studio 2013 Professional Update 5.

The following example code fails to compile with error C3848. However, if you change the call to std::bind to boost::bind, then the code compiles as expected.

#include< functional >
#include< ppl.h >
//#include< boost/bind.hpp >

class foo {
public:
    bool function() const {
        return true;
    }
};

int main(int argc, char* argv[]) {
    foo f;
    Concurrency::parallel_for(0, 5, std::bind(&foo::function, &f));
    //Concurrency::parallel_for(0, 5, boost::bind(&foo::function, &f));
    return 0;
}

I was expecting std::bind and boost::bind to be fully interchangeable, but that doesn't appear to be the case.

Can anyone suggest how to get the above example to compile using std::bind?

Aucun commentaire:

Enregistrer un commentaire