Boost logo

Boost :

Subject: Re: [boost] [Smart Ptr][Bind] Implementaion of Weak Callback Function
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2009-03-22 14:11:46

Artyom wrote:
>> weak_ptr< A > p;
>> bind(&A::foo, throw_if_invalid(p));
>> bind(&A::foo, ignore_if_invalid(p));
>> bind(&A::foo, call_if_invalid(p, bar)); // bar
> I think this is little bit problematic, because proxy
> weak_ptr_caller should know the signature of A::foo
> to provide correct "R operator()(args...)"

It will know it since it's instantiated from
weak_ptr_proxy::operator->*, which is called with the bound function

> Maybe, additional policy for weak_fn would be better
> void A::foo(int);
> function<void(int)> bar;
> bind(weak_fn(&A::foo,p),_1); // default ignore
> bind(weak_fn(&A::foo,p,throw_on_invalid()),_1);
> bind(weak_fn(&A::foo,p,bar),_1); // call bar on invalid
> This would not require changes in bind and also
> weak_fn would be useful without bind as well.
> Like function<void(int)> foobar=weak_fn(&A::foo,p);
> It would be simple to update weak_fn to add policy

I find this interface inconsistent with mem_fn. If this approach is
chosen, I'd vote to change the naming in order to reduce confusion.

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