0

How do I compare if two function objects hold the same function reference?

struct A {
    void b(){}
}
int main() {
    A a;
    auto f1 = std::bind(&A::b, a);
    auto f2 = std::bind(&A::b, a);

    f1 == f2 // ???
}
Appleshell
  • 7,088
  • 6
  • 47
  • 96
  • What error do you get from this? – Mats Petersson Sep 15 '13 at 13:54
  • You can, to a certain degree, compare `std::function` objects (via `function::target`). However, this doesn't work portably for `std::bind`-expressions, as their type is implementation-defined. – dyp Sep 15 '13 at 14:06

1 Answers1

1

Result of std::bind guarantees only to be callable and to have member type result_type. There is no standard-conformant way to compare binded functions.

Return value

A function object of unspecified type T, for which std::is_bind_expression::value == true, and which can be stored in std::function. The object is movable if f and all args are movable, and is copyable otherwise. The type defines the following members:

from http://en.cppreference.com/w/cpp/utility/functional/bind

sasha.sochka
  • 14,395
  • 10
  • 44
  • 68