0

How can I compare two std::function?

== only seems to compare to a null pointer: http://en.cppreference.com/w/cpp/utility/functional/function/operator_cmp

jviotti
  • 17,881
  • 26
  • 89
  • 148
  • related: http://stackoverflow.com/questions/3629835/why-is-stdfunction-not-equality-comparable – Pubby Apr 02 '13 at 04:27

1 Answers1

1

It isn't possible. std::function can store any copyable and callable object. This includes objects that are not comparable. Since std::function can contain objects that are not comparable, it cannot provide any comparison operations that will work for all contained objects.

If you want this functionality, you'll have to implement your own type-erased function template that requires the contained objects to be comparable.

Mankarse
  • 39,818
  • 11
  • 97
  • 141