Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-11-21 08:11:00

From: "ERICSSON,JOHAN (A-Sonoma,ex1)" <johan_ericsson_at_[hidden]>

[intrusive varant<> version handles construction from orinary

> Anyways, I like the 'variant' method much better than the clone() method
> everywhere. This just seems to be one place where it is less flexible than
> the clone() method.

True. This applies to shared_ptr<> as well. I recently had to implement an
intrusive shared pointer (based on add_ref/release) since it can be safely
constructed from a raw pointer. This is useful in situations where you have
a method

class X

    virtual smart_ptr<drag_handler> beginDrag();


and you need to return 'this' from beginDrag since X is-a drag_handler.

In general, non-intrusive versions are harder to implement, however, so it
makes sense to provide them first (in boost.)

> > variant<void> is (very) similar to any.
> That is interesting. The 'variant' can be used to simulate an 'any' class.
> Is there a name to describe the idiom common to both the 'any' and the
> 'variant' class?

I don't know. The technique they use is known as "external polymorphism."

Peter Dimov
Multi Media Ltd.

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