Boost logo

Boost :

Subject: Re: [boost] Weak functor: Interested? (How to boost::bind to a weak_ptr)
From: Roman Perepelitsa (roman.perepelitsa_at_[hidden])
Date: 2012-01-11 08:54:30


2012/1/11 Stewart, Robert <Robert.Stewart_at_[hidden]>

> shared_ptr doesn't overload ->* which, I thought, was the purpose of
> get_pointer().
>

ptr_adapter overloads ->*.

The fix of the code at
http://lists.boost.org/boost-users/2011/09/70647.phpis quite simple.

1. Replace raw pointers with weak_ptr in invoker and ptr_adaptor.
2. get_pointer becomes:

        template<class T>
        ptr_adapter<T> get_pointer(const boost::weak_ptr<T> &p)
        {
                return ptr_adapter<T>(p);
        }

3. invoker::operator() becomes:

R operator()() const
{
    if (shared_ptr<C> p = ci_.first.lock())
          return (p.get()->*ci_.second)();
    else
        return R();
}

Roman Perepelitsa.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk