Конструктор jthread в MSVC, похоже, неправильно вводит stop_token [дубликат]C++

Программы на C++. Форум разработчиков
Ответить
Anonymous
 Конструктор jthread в MSVC, похоже, неправильно вводит stop_token [дубликат]

Сообщение Anonymous »

Я новичок в jthreads, поэтому извините, если на мой вопрос есть очевидный ответ, который я пропустил.
Согласно онлайн-документации и второму пилоту github, я должен иметь возможность создать jthread, запускающий статическую функцию-член
void myClass::f(std::stop_token stopTok, HANDLE handle, std::chrono::milliseconds timeout)
вот так
std::jthread jt{ &myClass::f, pipeHandle, _timeout };.
Насколько я понял, происходит какое-то метапрограммирование шаблонов, которое я не совсем понимаю, но в результате должно быть, что член jthread stop_token передается в качестве первого параметра в f.
В MSVC это не так, на что жалуется компилятор
error C2672: 'invoke': no matching overloaded function found
Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Ty1 &&,_Types2 ...) noexcept()'
Не соответствует ли здесь Microsoft стандартам? Я не пробовал точный код на другом компиляторе, но, похоже, он работает на g++.
Заранее спасибо!
Изменить: минимальный воспроизводимый пример
#include
#include

struct myClass
{
void createThread()
{
int result = 0;
std::jthread jt{&myClass::threadFunc, 2, 3, result};
jt.request_stop();
}

static void threadFunc(std::stop_token stok, int i1, int i2, int& i3)
{
std::this_thread::sleep_for(std::chrono::milliseconds(500));
i3 = i1 + i2;
}
};

int main()
{
myClass mc;
mc.createThread();
return 0;
}

Вывод>
C:\Program Files\Microsoft Visual Studio\18\Professional\VC\Tools\MSVC\14.50.35717\include\thread(60): error C2672: 'invoke': no matching overloaded function found
C:\Program Files\Microsoft Visual Studio\18\Professional\VC\Tools\MSVC\14.50.35717\include\type_traits(1682): note: could be 'unknown-type std::invoke(_Callable &&,_Ty1 &&,_Types2 ...) noexcept()'
C:\Program Files\Microsoft Visual Studio\18\Professional\VC\Tools\MSVC\14.50.35717\include\thread(60): note: Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Ty1 &&,_Types2 ...) noexcept()'
C:\Program Files\Microsoft Visual Studio\18\Professional\VC\Tools\MSVC\14.50.35717\include\thread(60): note: With the following template arguments:
C:\Program Files\Microsoft Visual Studio\18\Professional\VC\Tools\MSVC\14.50.35717\include\thread(60): note: '_Callable=void (__cdecl *)(std::stop_token,int,int,int &)'
C:\Program Files\Microsoft Visual Studio\18\Professional\VC\Tools\MSVC\14.50.35717\include\thread(60): note: '_Ty1=int'
C:\Program Files\Microsoft Visual Studio\18\Professional\VC\Tools\MSVC\14.50.35717\include\thread(60): note: '_Types2={int, int}'
C:\Program Files\Microsoft Visual Studio\18\Professional\VC\Tools\MSVC\14.50.35717\include\type_traits(1685): note: 'std::_Invoker_functor::_Call': no matching overloaded function found
C:\Program Files\Microsoft Visual Studio\18\Professional\VC\Tools\MSVC\14.50.35717\include\type_traits(1582): note: could be 'unknown-type std::_Invoker_functor::_Call(_Callable &&,_Types ...) noexcept()'
C:\Program Files\Microsoft Visual Studio\18\Professional\VC\Tools\MSVC\14.50.35717\include\type_traits(1676): note: or 'unknown-type std::invoke(_Callable &&) noexcept()'
C:\Program Files\Microsoft Visual Studio\18\Professional\VC\Tools\MSVC\14.50.35717\include\thread(60): note: 'unknown-type std::invoke(_Callable &&) noexcept()': expects 1 arguments - 4 provided
C:\Program Files\Microsoft Visual Studio\18\Professional\VC\Tools\MSVC\14.50.35717\include\thread(60): note: the template instantiation context (the oldest one first) is
C:\Users\name\Desktop\jthread\jthread.cpp(9): note: see reference to function template instantiation 'std::jthread::jthread(_Fn &&,int &&,int &&,int &)' being compiled
with
[
_Fn=void (__cdecl *)(std::stop_token,int,int,int &)
]
C:\Program Files\Microsoft Visual Studio\18\Professional\VC\Tools\MSVC\14.50.35717\include\thread(359): note: see reference to function template instantiation 'void std::thread::_Start(_Fn &&,_Ty &&,_Ty &&,int &)' being compiled
with
[
_Ty=int,
_Fn=void (__cdecl *)(std::stop_token,int,int,int &)
]
C:\Program Files\Microsoft Visual Studio\18\Professional\VC\Tools\MSVC\14.50.35717\include\thread(76): note: see reference to function template instantiation 'unsigned int (__cdecl *std::thread::_Get_invoke(std::integer_sequence) noexcept)(void *) noexcept' being compiled
C:\Program Files\Microsoft Visual Studio\18\Professional\VC\Tools\MSVC\14.50.35717\include\thread(67): note: see reference to function template instantiation 'unsigned int std::thread::_Invoke(void *) noexcept' being compiled

Build finished with error(s).


Подробнее здесь: https://stackoverflow.com/questions/798 ... -correctly
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C++»