I think the answer to this is no, but I just want to be sure.
If I have a std::function
as a parameter in a function, is there any problem with passing in a boost::bind
and vice-versa?
edit:
I discovered that the placeholders used by boost::bind are imported directly into the namespace when you include boost\bind.h, and they are incompatible with std::bind. For std::bind you have to refer to the placeholders explicit, like so: std::placeholders::_1, or do some other typedef or using magic to make them both available simultaneously.
std::bind. The function template bind generates a forwarding call wrapper for f . Calling this wrapper is equivalent to invoking f with some of its arguments bound to args .
_1 is a placeholder. Boost. Bind defines placeholders from _1 to _9 . These placeholders tell boost::bind() to return a function object that expects as many parameters as the placeholder with the greatest number.
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).
The std::placeholders namespace contains the placeholder objects [_1, ..., _N] where N is an implementation defined maximum number.
No. The whole purpose of std::
(and boost::
) function
is that they can accept any function object which can be called with the correct signature- including lambdas, functors, and the result of any kind of binding. They do not care where your function object came from or what type it is.
You can even bind them to each other, although I'm not really sure why you'd want to.
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