#include <functional>
#include <string>
#include <iostream>
struct Foo
{
bool comp(const Foo& a)
{
std::cout << "a = " << a.s << std::endl;
return a.s == s;
}
std::string s;
};
struct Bar
{
int a;
};
template <class F, class T>
void execute (F f, T a)
{
std::cout << "Result: " << f (a) << std::endl;
}
int main()
{
Foo* f1 = new Foo;
f1->s = "Hello";
Foo f2;
f2.s = "Bla";
Bar b;
b.a = 100;
execute (std::bind2nd (std::mem_fun(&Foo::comp), b), f1);
return 0;
}
I2luY2x1ZGUgPGZ1bmN0aW9uYWw+CiNpbmNsdWRlIDxzdHJpbmc+CiNpbmNsdWRlIDxpb3N0cmVhbT4KCnN0cnVjdCBGb28KewogICAgYm9vbCBjb21wKGNvbnN0IEZvbyYgYSkKICAgIHsKICAgIAlzdGQ6OmNvdXQgPDwgImEgPSAiIDw8IGEucyA8PCBzdGQ6OmVuZGw7CiAgICAJcmV0dXJuIGEucyA9PSBzOwogICAgfQogICAgCiAgICBzdGQ6OnN0cmluZyBzOwoJCn07CgpzdHJ1Y3QgQmFyCnsKICAgIGludCBhOwp9OwoKCnRlbXBsYXRlIDxjbGFzcyBGLCBjbGFzcyBUPgp2b2lkIGV4ZWN1dGUgKEYgZiwgVCBhKQp7CiAgICBzdGQ6OmNvdXQgPDwgIlJlc3VsdDogIiA8PCBmIChhKSA8PCBzdGQ6OmVuZGw7Cgp9CgppbnQgbWFpbigpCnsKICAgIEZvbyogZjEgPSBuZXcgRm9vOwogICAgZjEtPnMgPSAiSGVsbG8iOwogICAgCiAgICBGb28gZjI7CiAgICBmMi5zID0gIkJsYSI7CiAgICAKICAgIEJhciBiOwogICAgYi5hID0gMTAwOwogICAgCiAgICBleGVjdXRlIChzdGQ6OmJpbmQybmQgKHN0ZDo6bWVtX2Z1bigmRm9vOjpjb21wKSwgYiksIGYxKTsKICAgIAogICAgCiAgICByZXR1cm4gMDsKfQ==