Чтобы попытаться получить немного производительности за небольшие деньги, я пытаюсь использовать конкретный тип исполнителя asio::io_service::executor_type вместо полиморфного asio::any_io_executor.
Вот пример:
Код: Выделить всё
using executor_type = asio::io_context::executor_type;
using udp_resolver_type = asio::ip::basic_resolver;
asio::io_context ctx;
udp_resolver_type resolver{ctx};
asio::awaitable host_to_endpoint(std::string host) {
asio::ip::udp::resolver::query query{std::move(host), "1234"};
const auto endpoints = co_await resolver.async_resolve(query, asio::use_awaitable);
co_return *endpoints.begin();
}
Код: Выделить всё
error: no matching member function for call to 'await_transform'
13 | const auto endpoints = co_await resolver.async_resolve(query, asio::use_awaitable);
note: candidate function not viable: no known conversion from 'decltype(asio::async_initiate(declval(), token, q))' (aka 'awaitable') to 'this_coro::executor_t' for 1st argument
203 | auto await_transform(this_coro::executor_t) noexcept
... several other candidate functions ...
note: candidate template ignored: could not match 'asio::io_context::basic_executor_type' against 'asio::any_io_executor'
168 | auto await_transform(awaitable a) const
note: candidate template ignored: substitution failure [with Op = decltype(asio::async_initiate(declval(), token, q))]: no type named 'type' in 'asio::constraint'
177 | auto await_transform(Op&& op,
Мой вопрос: чтобы избежать затрат на полиморфный asio::any_io_executor, правильно ли я предположу, что функция host_to_endpoint< /code> должен возвращать asio::awaitable с аргументом шаблона конкретного E = executor_type? Если да, то как я могу исправить свой код, чтобы он компилировался конкретным исполнителем?
Подробнее здесь: https://stackoverflow.com/questions/791 ... ompilation