ThijsM
ThijsM

Reputation: 200

Retrieve return value with lambda from boost::thread

Lately I read this post: How do I use boost.lambda with boost.thread to get the thread's return value?

I tried to implement the answer and it went fairly well except I get an error that I can't solve.

My code is this:

falcon::Mesh* falcon::ResourceManager::GetMesh(const std::string& id)
{
    Mesh* meshPtr;
    boost::thread meshLoadThread(boost::lambda::var(meshPtr) = bind(&MeshManager::LoadMesh, MeshManager::GetInstance(), id));
    meshLoadThread.join();
    return meshPtr;
}

But when I try to compile, I get the following error

error C2440: '=' : cannot convert from 
    'const std::tr1::_Bind<_Result_type,_Ret,_BindN>'
 to 'falcon::Mesh *'

I know it should work normally because in the example it works too! Anyone got any suggestions?

Upvotes: 3

Views: 680

Answers (2)

Viktor Sehr
Viktor Sehr

Reputation: 13099

How about using C++11x lambdas instead?

boost::thread meshLoadThread([&](){ meshPtr = MeshManager::GetInstance().LoadMesh(id); });

Upvotes: 2

interjay
interjay

Reputation: 110138

You are using bind from std::tr1 (the version that comes with Visual Studio).

You need to use the version of bind that is part of the Boost.Lambda library, i.e. boost::lambda::bind. Note that this is not the same as boost::bind.

You will need to #include <boost/lambda/bind.hpp>.

Upvotes: 3

Related Questions