Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if two std::function are Equal

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.

like image 957
danijar Avatar asked Oct 20 '12 15:10

danijar


People also ask

How to compare if two vectors are same C++?

C++ Vector Library - operator== Function The C++ function std::vector::operator== tests whether two vectors are equal or not. Operator == first checks the size of both container, if sizes are same then it compares elements sequentially and comparison stops at first mismatch.

What is std :: equal?

The C++ function std::algorithm::equal() tests whether two sets of element are equal or not. Size of the both set need not to be equal. It uses binary predicate for comparison.

How do you compare function pointers?

Two function pointers can be compared with the == and != operators, just like any other kind of pointers. We can also compare a function pointer to the NULL pointer using the == and != operators.


1 Answers

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

like image 145
Rahul Tripathi Avatar answered Sep 23 '22 19:09

Rahul Tripathi