What is the difference between Boost::bind and Boost Phoenix::bind?
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.
Boost. Phoenix supports functional programming with function objects: Functions are objects based on classes which overload the operator operator() . That way function objects behave like other objects in C++. For example, they can be copied and stored in a container.
_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.
The placeholders provide std::bind compatible placeholders that additionally provide basic C++ operators that creates bind expressions. Each bind expression supports constexpr function evaluation.
phoenix::bind
is like lambda::bind
a function that returns an expression template that records that it has to call the given function. These are designed to work together with phoenix and lambda, respectively. As a result, they contain much more things. Like, the type they return overloads all possible operators so that their respective action can be recorded and executed later.
boost::bind
is "just" a binder. It will bind the function, and return a type that has the function call operator overloaded, and not much more.
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