asio::experimental::use_promise requires the result type to be default constructible
I wrote an experimental TCP proxy with boost::asio and tried to replace all asio::use_awaitable with asio::experimental::use_promise in my code (as another experiment), and the following code stopped compiling:
asio::awaitable runProxy(tcp::endpoint listen_endpoint, ssl::context client_ctx,
const std::string& target_host, const std::string& target_port)
{
// Get the executor for the acceptor
auto exec = co_await asio::this_coro::executor;
tcp::acceptor acceptor(exec, listen_endpoint);
tcp::socket sock = co_await acceptor.async_accept(asio::experimental::use_promise);
// ..
}
MSVC error:
error C2512: 'boost::asio::basic_stream_socket<:asio::ip::tcp>': no appropriate default constructor available
The default constructor is called in boost_1_89_0\include\boost-1_89\boost\asio\experimental\impl\promise.hpp:
template
void cancel_impl_(boost::system::error_code*, T_*...)
{
complete(boost::asio::error::operation_aborted, T_{}...);
}
Does it mean that something was done carelessly in boost::asio?
It looks disappointing that the cancellation requires construction of the result type.
Read more here: Source link
