Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2000-09-01 07:37:02


> For this I have tended to use a cloning smart pointer, so that copy
> semantics are deep. Operational usage is pointer-like, because we can't
> overload operator., so I tend to classify it as a smart pointer.

But ref<T> is a cloning smart pointer. So is any, for that matter. :) In C++
we are limited to op-> and smart references are impossible.

The difference is that (1) you can use ref<> as is with standard containers
and algorithms and it just works, and (2) you don't give raw pointers
(obtained with new) to ref<>, it takes the values themselves.

ref<> supports my vision that 'new' and 'delete' have no place in user code.
The only place where I was forced to use 'new' was to manage containers of
polymorphic objects, so I decided to eliminate it.

Then I realized that ref<void> can (strictly speaking, can be made to) hold
any value (I wasn't aware of your 'any' class at the time.)

> In this case, providing operator== and operator< for a cloning pointer
> does the trick.

ref<> is a cloning pointer and I did provide op== and op<. :)

> >It's a side effect of the implementation. I don't like unnessary
couplings,
> >so I decided not to pull in <typeinfo>.
>
> I think that in this case, depending on that part of the standard is not
> such a problem.

No, it's not a problem per se. The point is that I didn't need <typeinfo>.

> >ref<> is not a converting creature. It's the thing you use when you want
a
> >std::vector (or std::set) of polymorphic objects.
>
> Again, I have used a cloning pointer to get this effect.

You mean, you used your own cloning pointer. :)

> So, I think there's a couple of things that come out of this:
>
> (1) Should we reopen the case for (or against) a cloning pointer? IIRC
> there was some discussion on this earlier this year / late last year,
> and then it fizzled out.
>
> (2) Look at variant value class distinct from any that is more
> permissive in its operations, ie not just a passive container. Peter,
> interested in taking this further?

(1) A polymorphic value type is useful, can there be any debate on that?
Regardless of whether it's called a cloning pointer, a smart reference or
ref<T>.

(2) Would you mind to elaborate further on that?

In summary, do you think that it will be worth the effort to unify any and
ref<T>, supporting the current idioms of ref<T> as a cloning value-based
smart pointer and any == ref<void> as, well, a cloning value-based smart
pointer without a common base requirement? Or these two concepts should
remain separate.

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