Boost logo

Boost :

From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2002-07-26 22:10:29


Andrei Alexandrescu wrote:
> > Not a C++ union. Consider using a 'variant' class :).
>
> But of course you can build a C++ union of all types in a
> typlist (unless I misunderstood the question). Unions can be templates.

Sure, but you cannot inherit them (the usual way to get several members into
a single class).

> See the template union ConfigurableUnion in
ftp://ftp.cuj.com/pub/2002/2008/alexandr.zip.

Oh, I see. But it's not a union, it's a union of union of union etc.; e.g.
for the type sequence [int, long, char, double] you code will produce

union
{
    int head_;
    union
    {
        long head_;
        union
        {
            char head_;
            union
            {
                double head_;
            } tail_;
        } tail_;
    } tail_;
};

instead of

union
{
    int i;
    long l;
    char c;
    double d;
};

I am not sure of the implications, though :). Anyway, it's good to know,
thanks.

Aleksey


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