>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
>case).
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.
>> 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.
(If
you really want to hide it from clients of your class, then use the
PIMPL idiom.)