Boost logo

Boost :

Subject: Re: [boost] An extension to boost::variant
From: Chris Hamilton (chamilton_at_[hidden])
Date: 2009-02-09 08:36:22


>> ..My question is this: why can't boost::variant be clever about reference
>> data types..

> An example will be better than a lengthy explanation,
> please have a look at the test-cases in the boost distribution:
> libs/variant/test/:
> specially variant_reference_test.cpp
>
> IMHO, it will answer all your queries.

Hmm... that doesn't seem to answer my question. boost::variant
currently can not handle the following code:

struct foo {};

int main(int argc, const char** argv)
{
    foo f;
    foo* pf = &f;

    boost::variant<foo*,foo&> v;

    v = f;
    printf("%d\n", &boost::get<foo&>(v) == &f);

    v = pf;
    printf("%d\n", boost::get<foo*>(v) == pf);

    pf = NULL;
    printf("%d\n", boost::get<foo*>(v) != pf)

    return 0;
}

My question is essentially this: why couldn't it?

Regards,

Chris


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