Boost logo

Boost :

Subject: Re: [boost] [variant] match()
From: Peter Dimov (lists_at_[hidden])
Date: 2015-01-09 13:16:15

Eelis wrote:
> Really, variant<> should have been index-based all along, so that you can
> just do get<0> and get<1> on a variant<T, T> (or a variant<A, B> where A
> might be B) without losing information.

Adding get<I> to variant is trivial - it already stores the index and
exposes it in which(). But you can't store anything into variant<T,T>
because constructors and assignment dispatch by type.

We could in principle add something like

    variant<T,T> v( index<0>, t );


    v.assign( index<0>, t );


    variant<T,T> v( _1, t );
    v.assign( _1, t );


    v = t;

is never going to work. The best we could do is

    v = { _1, t };

Boost list run by bdawes at, gregod at, cpdaniel at, john at