#include <functional>
#include <iostream>
class Tracker
{
public :
Tracker( ) : _methodCalled( false ) { }
void MethodToCall( )
{
std:: cout << "Method called\n " ;
_methodCalled = true ;
}
bool GetMethodCalled( ) const
{
return _methodCalled;
}
private :
bool _methodCalled;
} ;
int main( )
{
Tracker trackerToCopy;
auto boundToCopy = std:: bind ( & Tracker:: MethodToCall , trackerToCopy) ;
std:: cout << "Bound to copy of tracker\n \t " ;
boundToCopy( ) ;
std:: cout << "\t _methodCalled value: " << ( trackerToCopy.GetMethodCalled ( ) ? "true" : "false" ) << std:: endl ;
Tracker trackerLocalInstance;
auto boundToLocalInstance = std:: bind ( & Tracker:: MethodToCall , & trackerLocalInstance) ;
std:: cout << "Bound to local instance of tracker\n \t " ;
boundToLocalInstance( ) ;
std:: cout << "\t _methodCalled value: " << ( trackerLocalInstance.GetMethodCalled ( ) ? "true" : "false" ) << std:: endl ;
Tracker trackerReference;
auto boundToReference = std:: bind ( & Tracker:: MethodToCall , std:: ref ( trackerReference) ) ;
std:: cout << "Bound to refrence to tracker\n \t " ;
boundToReference( ) ;
std:: cout << "\t _methodCalled value: " << ( trackerReference.GetMethodCalled ( ) ? "true" : "false" ) << std:: endl ;
return 0 ;
}
I2luY2x1ZGUgPGZ1bmN0aW9uYWw+CiNpbmNsdWRlIDxpb3N0cmVhbT4KCmNsYXNzIFRyYWNrZXIKewpwdWJsaWM6CiAgICBUcmFja2VyKCkgOiBfbWV0aG9kQ2FsbGVkKGZhbHNlKSB7fQoKICAgIHZvaWQgTWV0aG9kVG9DYWxsKCkKICAgIHsKICAgICAgICBzdGQ6OmNvdXQgPDwgIk1ldGhvZCBjYWxsZWRcbiI7CiAgICAJX21ldGhvZENhbGxlZCA9IHRydWU7CiAgICB9CiAgICAKICAgIGJvb2wgR2V0TWV0aG9kQ2FsbGVkKCkgY29uc3QKICAgIHsKICAgICAgICByZXR1cm4gX21ldGhvZENhbGxlZDsKICAgIH0KCnByaXZhdGU6CiAgICBib29sIF9tZXRob2RDYWxs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