Important update : Apparently, I made the wrong conclusion when I asked this question. Thanks to the answers I discovered, the lambda function [=]()works fine in a multi-threaded scenario. I apologize for raising this confusing question. Please vote to close, as this is not a problem.
In our company, we wrote a library function for asynchronously calling a function in a separate thread. It works using a combination of inheritance and magic patterns. The client code is as follows:
DemoThread thread;
std::string stringToPassByValue = "The string to pass by value";
AsyncCall(thread, &DemoThread::SomeFunction, stringToPassByValue);
Since the introduction of lambda functions, I would like to use it in combination with lambda functions. I would like to write the following client code:
DemoThread thread;
std::string stringToPassByValue = "The string to pass by value";
AsyncCall(thread, [=]()
{
const std::string someCopy = stringToPassByValue;
});
: , , , .
Visual ++ 2010 . , stringToPassByValue . " " . , , stringToPassByValue , , .
, : - ?
. :
DemoThread thread;
std::string stringToPassByValue = "The string to pass by value";
AsyncCall(thread, [=](const std::string stringPassedByValue)
{
const std::string someCopy = stringPassedByValue;
}
, stringToPassByValue);
, .
a >
: AsyncCall . , , AsyncCall , -. , Execute(), AsyncCall() . , Execute(), , .