Boost logo

Boost :

From: Joel de Guzman (djowel_at_[hidden])
Date: 2003-08-27 10:43:55


Alexander Nasonov <alnsn-mycop_at_[hidden]> wrote:
> Alexander Nasonov wrote:
>
>> With a tuple<> the situation is different because tuple<T&> is just
>> a class with a reference data member, and the language specifically allow
>> data members to be references but by means of special rules.
>> Since references are not objects, when you have a reference data member
>> you're not necessarily adding the data member to the class storage
>> (even though most implementations do just that).
>
> You can think of tuple<int&,char&> as it were
>
> struct tuple_int_char
> {
> int& m0;
> char& m1;
> // ...
> };
>
> variant<int&,char&> would be
>
> union variant_int_char
> {
> int& m0; // compile error
> char& m1;
> // ...
> };
>
> Despite this analogy I think variant<int&,char&> would be nice. I'm not

I think the problem is that we are hooked to this analogy and limit ourselves
with the limitations of this analogy. This analogy is very weak. Consider:

    union U
    {
        int x; // ok
        non_POD obj; // whoops!
    };

Yet, we do allow non-PODs with optional and variant.

> insisting though because you can always use reference_wrapper.

Yes you can, as a matter of fact, I can also use reference_wrapper with
tuples if Jaakko will insist that I can't use references. I'm glad he decided
to allow references. Maybe it's because of the analogy-to-a-struct thing.
But really, athough a tuple can be represented (implemented) as a struct,
that's just an issue of implementation.

-- 
Joel de Guzman
http://www.boost-consulting.com
http://spirit.sf.net

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