Boost Users :
Subject: Re: [Boost-users] [asio] wrap lambda async_receive call
From: Cheng Mo (chmhou_at_[hidden])
Date: 2015-03-25 03:48:23
>The compiler will build the code for a lambda only once regardless of
>how many times it's called. But it also won't let you create a
>recursive lambda, which is what you would need if you wanted to have a
>read operation repeat itself when it completes (which is the most common
I supposed that which would be built once durning compiling time but multi time in running time, wasn't it ?
It will implement every time when async_xxx be invoded. Although I was not do test for proving that.
>Well, actually that's not quite true -- you can type-erase a lambda via
>std::function or similar and then call it recursively. But AFAIK you
>can only do this when capturing by reference, and you can't safely do
>that with a locally declared lambda when making async calls. So it's
>not really useful in this context.
Private member function or std::function type various and transmitted as reference could be better in this case.
>> It's better that build a function object in static. What do you think ?
>Function objects have a similar lifetime issue, and making one static is
>potentially dangerous if you could have multiple operations or
>connections running concurrently. It's usually simplest to use a
>private method of the containing class, which is what most of the
>example code does.
You are right, the static is dangerous in multiple op and concurrence, Thanks.
(If you really want to hide it from clients of your class, then use the
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net