Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2003-09-16 22:16:05

Howard Hinnant <hinnant_at_[hidden]> writes:

> 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.

It is more consistent to be convenient ;-)

As I believe Peter said recently, "bind is all about convenience".

> And if assign<T> was commonly available, the inconvenience appears
> to be small.

But it ain't.

Is it useful for anything other than the complicated expression you
cite above? If so, maybe it should be.

> 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.

Sorry, you lost me.

> So the motivation for my question is: Is there sufficient motivation
> to make an exception out of member data pointers, thus complicating
> the interface?

Seems like a simplification to me.

Dave Abrahams
Boost Consulting

Boost list run by bdawes at, gregod at, cpdaniel at, john at