Boost logo

Boost :

From: Eric Friedman (ebf_at_[hidden])
Date: 2003-08-29 15:33:26


Joel,

Joel de Guzman wrote:
[snip]
> Also, is there a reason why we can't allow:
>
> variant<int&, double&> var;

Nothing fundamental no, just some additional metaprogramming ;) It's
supported now (see variant_reference_test).

See below for a note on the semantics of the resultant variant type, though.

> IIUC, internally, it's just a matter of storing a boost.reference_wrapper
> if T is a reference.

Well, IMO reference_wrapper isn't exactly the right solution since it is
Assignable whereas references aren't. So I introduced (in the variant detail
namespace) reference_content. It stores a reference, but allows placement
new to occur in the variant implementation.

The ultimate result of all this: variant< int& > is not Assignable, while
variant< reference_wrapper<int> > is. I believe this is as it should be, but
please disagree if you don't.

[snip]
> Am I missing something?
>
> TIA,
> --
> Joel de Guzman

Nope, thanks for the idea.

Eric


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