Boost logo

Boost :

From: David B. Held (dheld_at_[hidden])
Date: 2002-07-08 20:00:14


"Paul Mensonides" <pmenso57_at_[hidden]> wrote in message
news:000f01c226d1$b24cc070$7772e50c_at_c161550a...
> [...]
> Not really because of the return type per se. The problem is
> pointers-to-member-functions.

By "return type", I meant the return type of operator->*(), which must
be a closure. I was used to operator->() which only needs to return T*,
and was hoping a similarly simple implementation would be possible
for operator->*(). However, I see that operator->*() needs to return
a much more complicated beast.

> [...]
> This is only the case with pointers-to-member-functions though. In the
> sample that I sent previously, the mechanism hijacks the case where
> its a pointer-to-data-member and returns the result directly.

That's very nice. You're way ahead of me. ;) I was only concerned with
pointer-to-member-function, but it makes sense that the operator should
also work with data members.

> In essence though, this really *is* a closure facility that can be used
> outside of smart pointers:
>
> struct X {
> int f(int, int);
> };
>
> int main(void) {
> X* px = new X;
> typedef int (X::* pf_t)(int, int);
>
> pf_t pf = &X::f;
>
> closure<pf_t> cl(px, pf);
>
> // ...
>
> cl(2, 3);
>
> // ...
>
> delete px;
> return 0;
> }

Or...

boost::function<int, int, int> cl;
cl = boost::bind(&X::f, px);

Since the work is already done, how do we use function and bind
to get what we want?

It looks to me like boost::function makes this difficult, because it
encodes the types of the arguments in different template parameters,
instead of as one parameter like you have done. Perhaps an
actual independent closure library is appropriate here. It is certainly
useful in several different contexts. You gonna finish what you started,
Paul; or are you going to make me struggle with it? ;)

Dave


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