+ 2

Thread class constructor

Hi I am having a doubt on how to have generic constructor that accept any function pointer. Let me try to provide more details. As we know, std::thread class can take function as argument . This means constructor of thread class has capability to accept function pointer. My query is how to have this as generic function pointer? We need to define data types for function pointer , but how it is taking care of all different signatures of function pointer for thread class constructor?

10th Nov 2023, 6:18 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
2 Respuestas
+ 3
It takes the function type as a template parameter (F), and the argument types as Variadic template parameters. It also checks if F is callable. Then using Variadic pack expansion you can simple pass on the arguments to the function when you are calling it. Something like this https://code.sololearn.com/cMOhoFv0Sz70/?ref=app Variadic templates AKA parameter pack: https://en.cppreference.com/w/cpp/language/parameter_pack
10th Nov 2023, 9:23 PM
XXX
XXX - avatar
0
Thank you
11th Nov 2023, 4:01 AM
Ketan Lalcheta
Ketan Lalcheta - avatar