mardi 28 novembre 2017

Compare std::function created with std::bind

Here is a toy example

#include <iostream>
#include <functional>

struct Obj
{
  int x;

  int foo()
  {
    return 42;
  }
};

int main()
{
  Obj a, b;
  std::function<int()> f1 = std::bind(&Obj::foo, &a);
  std::function<int()> f2 = std::bind(&Obj::foo, &b);
  std::function<int()> f3 = std::bind(&Obj::foo, &a);
  std::function<int()> f4 = std::bind(&Obj::foo, &b);
}

How can I verify that f1 == f3 and f2 == f4, where the == comparator, here, means that both std::function objects correspond to the same method of the same object?

Aucun commentaire:

Enregistrer un commentaire