Thread class constructor | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 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 Réponses
+ 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 Variadic templates AKA parameter pack:
10th Nov 2023, 9:23 PM
XXX - avatar
Thank you
11th Nov 2023, 4:01 AM
Ketan Lalcheta
Ketan Lalcheta - avatar