I saw that operator==from the std::functionabused more than once, and I had to explain what its real use.
For clarity, in favor of future readers here is the documentation.
The above documentation says that it:
Compares a std :: function with a null pointer. Empty functions (i.e. Functions without a called target) compare equal, non-empty functions compare unequal.
However, it std::functionalso has operator bool()( here is the documentation), which behaves almost the same and can be instead of a comparison my_func == nullptr.
In particular, it is said that he:
Checks whether * this object retains the objective function, i.e. not empty.
I don’t see a case where it can be used, and the other one does not fit well, so I can’t understand what the purpose is operator==, except that it can be misunderstood and used incorrectly once.
Is there a specific case when you can not use?
Are they interchangeable because they are actually the same, or does it make sense to have two different operators?
source
share