I'm trying to implement a basic signal/slots system. Everything is up and running but I'm trying to improve the usability of my implementation.
At the moment this is how you connect to a signal:
struct X
{
void memberFunction(int a, int b)
{
// do something
}
};
void globalStaticFunction(int a, int b)
{
// do something
}
// this is what the signal::connect function looks like at the moment
ConnectionHandle connect(std::function<RetType(Args...)> func);
int main()
{
// test instance
X x;
// example signal
Signal<void(int, int)> mySignal;
// connect a static function to the signal
mySignal.connect(&globalStaticFunction);
// connect a member function
// here we have to use std::bind to get a std::function
mySignal.connect(std::bind(&X::memberFunction, &x, _1, _2));
}
I would like to supply the user with an easier way to bind member functions. I had something like this in mind (similar to how Qt does it):
// prefered member function connect
// connect(instance_ptr, function_ptr)
mySignal.connect(&x, &X::memberFunction);
Is it possible to get a std::function object for a member function without using std::bind? If not, is there an easy way to generate the std::bind call with just the instance_ptr and the function_ptr for the member function?