std::function::target()
will retrieve a pointer to the stored callable object. And that's what you're trying to compare.
You must specify the expected stored type, and target()
will return nullptr
if the type does not match.
(This means that if std::function
holds a function pointer, target()
will return a pointer-to-a-function-pointer.)
auto f = Foo; // This pointer existed in an earlier version of the question
if (*it->target<decltype(f)>() == f) { // Success
See it work in Compiler Explorer
Note that because functions decay to function pointers:
*it->target< decltype(Foo) >() == Foo
will not work, because std::function
can not possibly be holding a copy of the function Foo
. You would need to decay the function, such as:
*it->target< std::decay_t<decltype(Foo)> >() == Foo
or:
*it->target< decltype(&Foo) >() == Foo