I tried to invoke std::thread
perfect forwarding constructor (template< class Function, class... Args > explicit thread( Function&& f, Args&&... args );
) with a pointer to function (NOT a pointer to member function), as shown in the following M(N)WE:
#include <thread>
#include <string>
static void foo(std::string query, int & x)
{
while(true);
}
int main() {
int i = 1;
auto thd = std::thread(&foo, std::string("bar"), i);
thd.join();
}
Live demo: https://godbolt.org/g/Cwi6wd
Why does the code not compile on GCC, Clang and MSVC, complaining about a missing overload of invoke
(or similar names)?
A function argument is a pointer to a function, so it should be a Callable
, right?
Please note: I know that using a lambda would solve the problem; I want to understand why the problem arises.
std::string
argument is not required.