samedi 3 août 2019

How does a list of std::function with variable arguments work

I have a list of functions declared as std::list< std::function< void()>> funcList; As far as I understand std::function< void()> is different from (for example) std::function< int(int)>. So then how is registerCB accepting arguments with varying signatures of std::function.

std::list<std::function<void()>> funcList;
void registerCB(std::function<void()>&& f) {
    funcList.push_back(f);
}
registerCB(std::bind(func1, 1));        
registerCB(std::bind(func2,"Test"));
registerCB(std::bind(func3));

where func1, func2, func3 are 3 functions with different argument list.

registerCB expects an argument of type function, so does funcList.

I saw a similar post - C++ std::function variable with varying arguments

But I could not find the explanation to the above question.

Aucun commentaire:

Enregistrer un commentaire