asio icon indicating copy to clipboard operation
asio copied to clipboard

Feature request: completion token adapter that optionally prepends a default constructed error_code

Open andrei-datcu opened this issue 3 years ago • 0 comments

Since channels were introduced, I've been having troubles fully utilizing the void specialzation:

// this is super useful, as it is backed just by an unsigned int rather than a full blown std::deque
asio::experimental::channel<void()> ch(ex);

// we can use it with a function-base completion token
ch.async_receive([](asio::error_code ec = {}) {
});
// note the default value of the parameter. without that we'd get a compile error,
// because channel<void()>::async_receive needs two signatures by default

// but how do we use it in a coroutine
co_await ch.async_receive(asio::use_awaitable); // this is a compile error
co_await ch.async_receive(asio::experimental::prepend_if(asio::use_awaitable, asio::error_code{})); // what I'm proposing

Basically, we could have prepend_if prepend a constant value if the operation requests a signature that does not have a parameter having the same decayed type. Would that fit asio's code base or is it considered a use case too particular to be considered? Just a yes/no answer would suffice as I can contribute a draft implementation if needed.

andrei-datcu avatar Aug 06 '22 18:08 andrei-datcu