C ++ 20 asio :: co_spawn - ограничения не определены - PullRequest
0 голосов
/ 03 мая 2020

Я пытался создать приложение, используя C ++ 20 сопрограммы и asio (без повышения). Поэтому я использую компилятор MSV C. Следующий фрагмент кода может быть скомпилирован с флагом /await:

#include <asio.hpp>
int main(){
    asio::io_context ioContext(1);
    asio::co_spawn(ioContext.get_executor(), []() -> asio::awaitable<void> { return {}; }, asio::detached);
    return 0;
}

Как только я добавлю флаг компилятора /std:c++latest, код больше не будет компилироваться. Вместо этого я получаю сообщение об ошибке:

...\_libs\asio-1.16.1\include\asio\async_result.hpp(289,1): error C7602: 'asio::async_result': the associated constraints are not satisfied (compiling source file main.cpp)
...\_libs\asio-1.16.1\include\asio\async_result.hpp(107): message : see declaration of 'asio::async_result' (compiling source file main.cpp)
...\_libs\asio-1.16.1\include\asio\impl\co_spawn.hpp(139): message : see reference to class template instantiation 'asio::detail::async_result_has_initiate_memfn<CompletionToken,asio::detail::awaitable_signature<asio::awaitable<void,asio::executor>>>' being compiled
        with
        [
            CompletionToken=const asio::detached_t &
        ] (compiling source file main.cpp)
...\main.cpp(4): message : see reference to function template instantiation 'auto asio::co_spawn<asio::io_context::executor_type,main::<lambda_1>,const asio::detached_t&>(const Executor &,F &&,CompletionToken,void *)' being compiled
        with
        [
            Executor=asio::io_context::executor_type,
            F=main::<lambda_1>,
            CompletionToken=const asio::detached_t &
        ]
...\_libs\asio-1.16.1\include\asio\async_result.hpp(288,36): error C2672: 'asio::detail::async_result_initiate_memfn_helper': no matching overloaded function found (compiling source file main.cpp)
...\_libs\asio-1.16.1\include\asio\async_result.hpp(290,1): error C3206: 'asio::detail::async_result_initiate_memfn_helper': invalid template argument for 'T', missing template argument list on class template 'asio::async_result' (compiling source file main.cpp)
...\_libs\asio-1.16.1\include\asio\async_result.hpp(281): message : see declaration of 'asio::detail::async_result_initiate_memfn_helper' (compiling source file main.cpp)

Как использовать новейшие функции C ++ и автономные функции asio coroutine? Я делаю что-то неправильно? Я что-то забыл?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...