Boost logo

Boost :

From: Yitzhak Sapir (yitzhaks_at_[hidden])
Date: 2002-06-12 05:02:35


> -----Original Message-----
> From: Douglas Gregor [mailto:gregod_at_[hidden]]

> When does one prefer the boost::any storage method instead of
> the on-stack
> method? The on-stack approach is a lightweight approach that closely
> resembles C-style unions; in the cases where variant objects
> are too large to
> put on the stack, the variant objects can easily be allocated
> on the heap
> (just like we would do with a C-style union). The only cases
> where on-stack
> allocation isn't feasible occur with recursive or incomplete
> types (discussed
> later...). So, I would say that we should only use on-stack
> allocation but
> allow an 'escape' to heap allocation for recursion and
> incomplete types.

boost::any also allows an infinite range of types that may not necessarily be incomplete. For example, you could have a union of all types that inherit from some common base type (Shape), or a union of any instantiation of a templated type (I wonder if it is possible to check the existence of a class as part of a templated type at compile time -- perhaps using the "has member" compile time test).


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