Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-07-09 13:34:46


From: "Giovanni Bajo" <giovannibajo_at_[hidden]>
> From: "David B. Held" <dheld_at_[hidden]>
>
> > Is it possible to create
> > a global operator->* that takes a shared_ptr, and calls bind()?
>
> Not with the C++ I know, but maybe I just don't know how :)

template<class T, class R, class U> function<R> operator->*(shared_ptr<T>
const & p, R (U::*pmf) ())
{
  return bind(pmf, p);
}

template<class T, class R, class U, class A1> function<R, A1>
operator->*(shared_ptr<T> const & p, R (U::*pmf) (A1))
{
  return bind(pmf, p, _1);
}

// + additional overloads

Not the most efficient implementation, but it works. The function<> is used
only to name the return type (and to get around the forwarding problem -
bind() things don't take rvalues as arguments.)

In a better C++ this would have been

template<class T, class R, class U> typeof( bind(pmf, p) )
operator->*(shared_ptr<T> const & p, R (U::*pmf) ())
{
  return bind(pmf, p);
}

but I digress. ;-)


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