If I have two std::function
s, 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.
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.
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.
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.
I dont think that they both can be compared. Here is an example to explain some points on std::function comparison
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With