std::function<SIG> can be built from many things that behave like functions, converting them to the corresponding std::function object.
In this case, void S::foo() behaves in the same way as the function void foo_x(S&) (since both of them require a call to S and it is possible to change S without returning anything). Therefore, std::function<void(S&)> provides a constructor for converting a member function into a function object. I.e.
std::function<void(S &)> func = &S::foo;
uses a constructor, something like std::function<void(S&)>( void(S::)() ) :) std::function<void(S&)>( void(S::)() ) , to create something equivalent:
void foo_x(S & s ) { return s.foo(); } std::function<void(S&)> func = foo_x;
Similarly
std::function<void(S * const)> func = &S::foo;
equivalently
void foo_x(S * const s ) { return s->foo(); } std::function<void(S* const )> func = foo_x;
through a constructor of the type std::function<void(S* const )>( void(S::)() ) .
Michael anderson
source share