|
Boost : |
From: Howard Hinnant (hinnant_at_[hidden])
Date: 2003-09-16 19:56:07
On Sep 16, 2003, at 5:48 PM, David Abrahams wrote:
> It would be convenient for me if mem_fn(pm) could be *called* to set
> the data member, as in:
>
> X x;
>
> mem_fn(&X::member)(x, value);
>
> That way, bind(&X::member, _1, value) would be useful.
Could you expound on your convenience factor with respect to what you
have proposed, and the following:
template <class T>
struct assign
{
typedef T& result_type;
template <class U>
T& operator()(T& t, const U& u) const
{return t = u;}
};
...
bind(assign<T>(), bind(&X::member, _1), value)(x);
Clearly what you have proposed is more convenient, but it seems less
consistent. And if assign<T> was commonly available, the inconvenience
appears to be small.
The motivation for my request is that bind(f, a1, a2, ... an) currently
has an invariant that f is a function-like object taking n parameters,
except if f is a member pointer, then a1 is a (smart) pointer or
reference to the object, and the function itself (if it is a function)
takes n-1 parameters. The degenerate case of f being a member data
pointer coincides nicely with a member function pointer taking 0
parameters.
So the motivation for my question is: Is there sufficient motivation
to make an exception out of member data pointers, thus complicating the
interface?
-Howard
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk