Boost logo

Boost Users :

From: Mohammad Nejati [ashtum] (ashtumashtum_at_[hidden])
Date: 2025-05-21 16:52:57


On Wed, May 21, 2025 at 7:52 PM Klebsch, Mario via Boost-users
<boost-users_at_[hidden]> wrote:
> There is no default value of Executor, so how does the template instantiation of basic_stream_socket<tcp> compile?

The default executor is specified a few lines above in the forward declaration:
template <typename Protocol, typename Executor = any_io_executor>
class basic_stream_socket;

> I cannot do socket.get_executor().context().post(…).

You don't need the context. You can write it like:
asio::post(socket.get_executor(), []() {});

Asio has changed the default executor of io_object types from
io_context::executor_type to any_io_executor, to make them easier to
use and reduce code bloat as there is no need for generating special
composed operations for each executor type. You can find that in the
change log:
https://www.boost.org/doc/libs/develop/doc/html/boost_asio/history.html#boost_asio.history.asio_1_18_0___boost_1_74

You can still use a concrete executor type if you want. It will of
course change the socket type:
using my_socket_t = typename
asio::ip::tcp::socket::rebind_executor<asio::io_context::executor_type>::other;

You can also use any_io_executor and access the concrete executor when
you know the underlying executor type:
asio::any_io_executor executor{ io_context };
executor.target<asio::io_context::executor_type>().something...


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