Boost C++ Libraries: Ticket #8714: Allow move-only handlers
https://svn.boost.org/trac10/ticket/8714
<p>
(See also <a class="ext-link" href="http://stackoverflow.com/questions/17211263"><span class="icon"></span>http://stackoverflow.com/questions/17211263</a>)
</p>
<p>
The requirement that handlers be copy constructible doesn't allow for the following idiom:
</p>
<pre class="wiki">void connection::send_response()
{
// block until previous response is sent
std::unique_lock<std::mutex> locker(response_mutex_);
// prepare response
response_ = "foo";
// send response back to caller. move the unique_lock into the binder
// to keep the mutex locked until asio is done sending.
asio::async_write(stream_,
asio::const_buffers_1(response_.data(), response_.size()),
std::bind(&connection::response_sent, shared_from_this(),
_1, _2, std::move(locker))
);
}
void connection::response_sent(const boost::system::error_code& err, std::size_t len)
{
if (err) handle_error(err);
// the mutex is unlocked when the binder is destroyed
}
</pre><p>
Please remove this restriction, there is no reason for it when using C++11.
</p>
en-usBoost C++ Libraries/htdocs/site/boost.png
https://svn.boost.org/trac10/ticket/8714
Trac 1.4.3cristi.cobzarenco@…Thu, 14 Aug 2014 12:19:13 GMT
<link>https://svn.boost.org/trac10/ticket/8714#comment:1 </link>
<guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8714#comment:1</guid>
<description>
<p>
Any progress/discussion on this? There's plenty of reasons to allow move-only constructors, another is to use stackless coroutines with moveable only members, such as a deadline_timer, without having to wrap everything in a shared_ptr, needlessly complicating the code for a coroutine.
</p>
</description>
<category>Ticket</category>
</item>
</channel>
</rss>