|
Boost Users : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2005-03-22 16:35:37
David Morrison wrote:
> Peter Dimov wrote:
>
>> Change this to boost::mem_fn( f )( a1, a2, a3 ) and you'll be there.
>
> Yep, that's much cleaner, thanks.
>
> I was hoping that there'd be some clever way to use type_traits to
> magically select the right way of invoking the function f. That way,
> one could have a (possibly enhanced version of?) apply.hpp so that
> code to invoke apply on a set of member and non-member functions
> would look the same.
On a reasonably conforming compiler, adding an overload to apply<> should
work:
template<class F, class A1, class A2, class A3>
result_type operator()
(F & f, A1 & a1, A2 & a2, A3 & a3) const
{
return f(a1, a2, a3);
}
// add this
template<class M, class T, class A1, class A2, class A3>
result_type operator()
(M T::* pm, A1 & a1, A2 & a2, A3 & a3) const
{
return mem_fn(pm)(a1, a2, a3);
}
It might be a good idea to add this to apply.hpp, but I would need to write
a test for apply<> first.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net