how to pass argument to std::function?
-
Monday, April 16, 2012 4:35 PM
experimenting with c++ 11 lambdas ...
How to add a parameter to the std::function in this example? ( and how to call such a function with arguments? )
function<void()> run = [] { for ( long c = 0 ; c < 100 ; ++c ) nerdscentral::performRun() ; };I want to use similar code that will run on another thread. I am hoping I can use parameters to the lambda function to pass variables to the background thread.
std::function<void()> run = [](HWND hIn ) { ::Sleep(10000) ; ::PostMessage(hIn, WM_CLOSE, 0, 0) ; };thanks,
All Replies
-
Monday, April 16, 2012 5:23 PM
chekc this link this may help you out
http://stackoverflow.com/questions/7909719/c0x-stdfunction-as-a-method-argument
- Marked As Answer by Steve Richter Monday, April 16, 2012 5:56 PM
-
Monday, April 16, 2012 5:43 PM
chekc this link this may help you out
http://stackoverflow.com/questions/7909719/c0x-stdfunction-as-a-method-argument
thank you. I need examples. This stuff is too dense for me.
the following code does not show a syntax error in vs11, but compiles with an error C2064: term does not evaluate to a function taking 1 arguments.
std::function<void(HWND)> run = [](HWND hIn ) { ::Sleep(10000) ; ::PostMessage(hIn, WM_CLOSE, 0, 0) ; }; Error 1 error C2064: term does not evaluate to a function taking 1 arguments C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xrefwrap 96 1 HookDllTester _VARIADIC_EXPAND_0X(_CLASS_RESULT_TYPE, , , , )
-
Monday, April 16, 2012 5:46 PM
On 4/16/2012 12:35 PM, Steve Richter wrote:
How to add a parameter to the std::function in this example? ( and how to call such a function with arguments? )
function<void()> run = [] { for ( long c = 0 ; c< 100 ; ++c ) nerdscentral::performRun() ; };function<void(long)> run = [](long bound) { for ( long c = 0 ; c < bound ; ++c ) nerdscentral::performRun() ; }; run(100);
Igor Tandetnik
- Marked As Answer by Steve Richter Monday, April 16, 2012 5:56 PM

