Boost logo

Boost :

From: Kevlin Henney (kevlin_at_[hidden])
Date: 2000-09-01 04:41:15


In message <003d01c01367$7064fe40$1d0524d4_at_pdimov>, Peter Dimov
<pdimov_at_[hidden]> writes
>Yes. ref<T> holds its value by a T*, so it can hold anything derived from T,
>or anything at all when T is void.
>
>> So does that make ref<t> more like a regular smart pointer type?
>
>It's similar to a smart pointer, yes... but it is a value type at the same
>time. :)

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.

For the void case I use any.

>ref<T> makes no assumptions about operator== and <. It doesn't work in all
>cases, but is close.

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

>Hmm. I think I'll just upload an example so you can take a look yourself.

Thanks.

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

Because you can get the raw pointer from a cloning pointer all the std
RTTI works straight out of the box w/ it.

The traits technique you have used is similar to the approach I used for
getting == and < to work on a different variant type, one that supported
some operators and conversions.

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

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

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


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