If I bind a function like this, using placeholders at the time of binding
std::bind(memberFunctionPointer, objectPointer, _1, _2);
Is it then possible to "rebind" it later to replace some / all of the placeholders, but without calling the function? I want to be able to pass in some parameters and then store it, to be invoked later on. (delayed callback)
std::bind is a Standard Function Objects that acts as a Functional Adaptor i.e. it takes a function as input and returns a new function Object as an output with with one or more of the arguments of passed function bound or rearranged.
Internally, std::bind() detects that a pointer to a member function is passed and most likely turns it into a callable objects, e.g., by use std::mem_fn() with its first argument.
boost::bind is a generalization of the standard functions std::bind1st and std::bind2nd. It supports arbitrary function objects, functions, function pointers, and member function pointers, and is able to bind any argument to a specific value or route input arguments into arbitrary positions.
std::bind return type The return type of std::bind holds a member object of type std::decay<F>::type constructed from std::forward<F>(f), and one object per each of args... , of type std::decay<Arg_i>::type, similarly constructed from std::forward<Arg_i>(arg_i).
You can bind
again:
auto f = std::bind(memberFunctionPointer, objectPointer, _1, _2);
auto g = std::bind(f, val1, val2);
g(); // (objectPointer->*memberFunctionPointer)(val1, val2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With