Boost logo

Boost Users :

Subject: Re: [Boost-users] boost::asio::asyn_accept handler
From: Christopher Pisz (christopherpisz_at_[hidden])
Date: 2017-03-29 13:41:39


So, your whole method looks like:

void start_accept()
    {
        tcp_connection::pointer new_connection =
            tcp_connection::create(acceptor_.get_io_service());

        std::function<void(const boost::system::error_code &error)>
callback = std::bind(&tcp_server::handle_accept, this, new_connection,
            std::placeholders::_1);

        acceptor_.async_accept(new_connection->socket(), callback);
    }

Seems to compile.

I really don't understand how we are binding arguments that the template
parameters did not specify the std::function to take.
Can I pass it a cow or a moose too and it won't care? As long as the
callback takes a cow and a moose?

I thought all arguments had to be specified in the template params.

On Wed, Mar 29, 2017 at 8:28 AM, Steven Watanabe via Boost-users <
boost-users_at_[hidden]> wrote:

> AMDG
>
> On 03/29/2017 07:07 AM, Christopher Pisz via Boost-users wrote:
> > If I change it to
> > std::function<void(const
> > boost::system::error_code &error)> callback = ...
> >
> > then the connection is not passed.
>
> Yes it is. The connection is stored inside the std::function.
>
> > If it is not passed, then there is no
> > way to store it, change its state, etc.
> > It is passed in the tutorial code, so why can't I pass it with
> > std::function?
> >
>
> In Christ,
> Steven Watanabe
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>



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