Boost logo

Boost :

From: Larry Evans (cppljevans_at_[hidden])
Date: 2005-01-05 12:32:06


On 01/04/2005 11:52 AM, christopher diggins wrote:
> I have written a union-style type similar to boost::variant which allows
[snip]
> 2. the data size is huge = summation of the size of the individual types
> plus sizeof(bool) * #types.

Could you use the method for our_storage_size in:

http://cvs.sourceforge.net/viewcvs.py/boost-sandbox/boost-sandbox/boost/indexed_types/composite_sum.hpp?rev=1.2&view=auto

To calculate the maximum of the individual sizes and then just
allocate storage for this max size?

[snip]
> union-list is that it uses and provides an index to access the type of
> its contents.

This, IMHO, is important. In the above indexed_types directory,
there's typemap_unsigned.hpp which allows using unsigned indices
instead of enumerations to access the elements. This was designed
to allow the convenience of mpl's sequences; however, it also
requires the possibly time consuming use of mpl's at_c and size.
I don't know if it's really a significant time consumer, but
it'd be nice if your method could somehow be adapted to avoid
this. I've tried to think of a way to use mpl's inherit_linearly;
however, I think it can't be done because, in order to use
indexed accesss, all the type arguments of the inherited classes
have to be identical except for the index. Maybe someone else
can think of a workaround?


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