|
Boost Users : |
Subject: Re: [Boost-users] ASIO async_accept() and c++2011 lambas
From: Igor R (boost.lists_at_[hidden])
Date: 2011-07-27 04:16:24
> I found this example for use the async_accept() method:
>
> void accept_handler(const boost::system::error_code& error)
> {
> Â if (!error)
> Â {
> Â Â // Accept succeeded.
> Â }
> }
>
> ...
>
> boost::asio::ip::tcp::acceptor acceptor(io_service);
> ...
> boost::asio::ip::tcp::socket socket(io_service);
> acceptor.async_accept(socket, accept_handler);
>
> It is possible use the async_accept with a (c++0x) lambda function instead
> of the function accept_handler()?
Sure, you can.
...async_accept(socket, [=] (const boost::system::error_code &error)
{doSomething();});
Or, in a more readable form:
auto handler = [=] (const boost::system::error_code &error)
{
doSomething();
};
...async_accept(socket, handler);
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