[bind] Need Help - Function Composition

Hello all,
I'm using boost::bind to get elegant code. Thank the author
for the great lib. I'm posting because I ran accross a small
problem with the following code.
My intention of the code is to find the element of a container
with the least abs value of a member (i_).
template

AMDG loadcom wrote:
<snip>
// helper function template<typename F> less_by_func
make_less_by_func(F func) { return less_by_func (func); } <snip>
int min_abs = std::min_element(a_list.begin(), a_list.end(), min2max::make_less_by_func( boost::function
( boost::bind<int>( std::ptr_fun(&std::abs<int>), boost::bind(&A::i_, _1) ) ) ) )->i_; std::cout << min_abs << std::endl; This code works fine, what I don't understand is why I couldn't remove the explicit construction of a boost::function
object and let compiler do the implicit conversion(construction) silently. That means the following code doesn't work: int min_abs = std::min_element(a_list.begin(), a_list.end(), min2max::make_less_by_func( boost::bind<int>( std::ptr_fun(&std::abs<int>), boost::bind(&A::i_, _1) ) ) )->i_;
The function objects created by Boost.Bind are plolymorphic. Thus, since
they can be called with multiple different argument types, there is no way
for them to provide an argument_type typedef. This means that in
template<typename F>
less_by_func
participants (2)
-
loadcom
-
Steven Watanabe