Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2000-11-22 16:06:05


From: "William Kempf" <sirwillard_at_[hidden]>

> --- In boost_at_[hidden], "Peter Dimov" <pdimov_at_m...> wrote:
> > A list of pros and cons won't help, because a cloning callback and a
> > reference counted callback are different concepts. Sometimes you'll
> need the
> > one, sometimes the other.
>
> This I'm not so sure about. Yes, their behavior is radically
> different. However, I find it difficult to think of specific
> situations where one would be the answer while the other would not.
> Can you spark my thinking on this?

The "pro ref-counting" example is easy, I already offered it (the STL
algorithms assume that copies are equivalent.)

To be honest, I don't immediately see a killer example that demonstrates a
situation where a cloning callback would be the answer but the counted
callback will not fit. Cloning just "feels right" to me.

The counted callback more closely mirrors a function pointer, in the case
where the function has state (static variables.)

All this seems to point toward reference counted semantics, but as I said,
my intuition doesn't agree. :-)

Here's another tricky point:

callback<int, int> c(F());
callback<void, char> c2(c);

Do c and c2 share the same function object?

(The prototype implementations, including mine, don't handle this case
"correctly", I believe, but for now, let's ignore them and look at the
design.)

Another question about the example above, suppose that F has two overloads:

struct F
{
    int operator()(int);
    void operator()(char);
};

Which op() should c2('A') call?

--
Peter Dimov
Multi Media Ltd.

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