Check if two std::function are Equal

2019-04-25 02:48发布

问题:

If I have two std::functions, how can I check whether both hold the same function or not?

Additional Information: I have a vector of functions std::vector<std::function<void()>> and before adding another function to the vector I want to check if it already is contained.

回答1:

I dont think that they both can be compared. Here is an example to explain some points on std::function comparison



回答2:

Generally std::function and boost::function are not comparable because they need their stored object be comparable but not all function objects and also lambdas have operator== so std or boost functions have no way to compare them