Boost logo

Boost :

From: Kevlin Henney (kevlin_at_[hidden])
Date: 2000-08-31 04:08:05


In message <009901c012af$971e5c60$420524d4_at_pdimov>, Peter Dimov
<pdimov_at_[hidden]> writes
>I've been working on a similar class. I called it ref<T> (although I like
>the name 'any') and it differs from your variant value in the following:
>
>* ref<T> is a polymorphic value type, i.e. you can use op-> on it to access
>T's virtual member functions.

So ref<t> assumes T is a base, but otherwise supports the copying etc
semantics? This contrasts with any which just works on values and
assumes no conversion relationship, so if you know exactly what T is
then to_ptr()->m works fine, but won't work if a hierarchy is assumed.

So does that make ref<t> more like a regular smart pointer type?

>* it has operator== and operator< to support std::sort and similar
>algorithms.

any makes few assumptions about its containee, and although I have a
version that has these, I am not entirely happy with it: either you
require == and < supported on all containee types, or you have a traits
class that allows the programmer to provide reasonable behaviour (or
non-behaviour) as necessary.

>* it has its own RTTI system and doesn't use (or require) type_info.

Was this for portability, or...?

>* ref<void> is similar to 'any' in functionality.

Parallel evolution :-)

>* It compiles on our all time favorite compiler.

Is that a benefit or...? ;-)

>I haven't spend much time on it and I don't think it's ready for submission,
>but if there is interest I can upload a work in progress (no docs, no
>optimizations - it is not reference counted at the moment and copies are
>expensive.)

Separate from any, I have also played around with a type that supports a
greater range of operations and conversions. In the docs I classified
variant types in one of three categories, with any qualifying as a
"discriminated type w/o conversions". A type that supports extra
operations and the like is in the "converting type" category. I think it
is worth having such a creature, but I think it's a different type.
____________________________________________________________

  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