Boost logo

Boost :

From: Kevlin Henney (kevlin_at_[hidden])
Date: 2000-11-22 17:39:52

In message <010201c054c9$1f4a5a20$360524d4_at_pdimov>, Peter Dimov
<pdimov_at_[hidden]> writes
>The "pro ref-counting" example is easy, I already offered it (the STL
>algorithms assume that copies are equivalent.)

Cloning also satisfies this, and mirrors the deep copying already used
in the STL. I think the STL only offers a split vote on this issue.

>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.

Ditto. However, where state modification occurs and we have the
intuition of functions being isolated, reference counting does the wrong
thing. And, of course, we simply add threads into this particular
scenario, and kerblam (sp?).

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

Not sure I agree that it does quite make this case. I think built-in
semantics are surprisingly neutral on the topic.

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

I guess, as I don't believe that reference-counted semantics are being
pointed to, my intuition is well aligned :-)

>Here's another tricky point:
>callback<int, int> c(F());
>callback<void, char> c2(c);
>Do c and c2 share the same function object?

I would say no, as they are distinct types.

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

Agreed, although my gut instinct tells me that it ain't gonna be a
problem :-)

>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?

Following the previous "no", operator()(int). Of course, a "yes" would
make it all rather tricky, but my compile time-polymorphism instincts
cling to "no" :-)


  Kevlin Henney phone: +44 117 942 2990
  Curbralan Limited mobile: +44 7801 073 508
  mailto:kevlin_at_[hidden] fax: +44 870 052 2289

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