Boost logo

Boost Users :

Subject: Re: [Boost-users] Variant and Fusion
From: Matthias Vallentin (vallentin_at_[hidden])
Date: 2010-03-10 19:45:23


On Wed, Mar 10, 2010 at 01:46:30PM -0800, Steven Watanabe wrote:
> Can you give an example of the kind of recursive variant and the
> sequence(s) that you want to get out of it?

Let this be the variant type

    typedef boost::make_recursive_variant<
        int,
        double,
        std::vector<boost::recursive_variant_>
>::type variant;

and this an instance of it

    std::vector<variant> vec;
    vec.push_back(42);
    vec.push_back(4.2);
    vec.push_back(vec);
    variant v = vec;

> In particular how are the runtime values of the elements of the
> sequence to be determined?

Conceptually, I am thinking of a visitor that goes over the variant and
flattens it. In the above example, the corresponding sequence would be

    [42, 4.2, 42, 4.2]

which corresponds to a fusion::vector<int, double, int, double>.
Practically, I don't see a way how to get the type of the vector at
runtime unless knowing in advance the type of the fusion vector (which
could be a potential assumption).

I was also talking about "chopping" the variant in disjunct sequences.
By this, I mean that a visitor goes over the variant and creates several
sequences, say

    [42]
    [4.2, 42]
    [42]

for the above example. That's the scenario I ultimately target. Ideally,
these sequences are only views (tiers) of the original variant.

> Depending on what you're doing, you might be able to use the nested
> types typedef of variant, which is an MPL sequence.

Are you referring to the variant<T>::types MPL sequence?

   Matthias

-- 
Matthias Vallentin
vallentin_at_[hidden]
http://www.icir.org/matthias

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net