Boost logo

Boost Users :

Subject: [Boost-users] [tuple][mpl][fusion] How to "prune" or "collapse" a tuple?
From: AJG (plus.ajg_at_[hidden])
Date: 2010-08-13 15:26:32


Hi all,

> [added this line to make gmane happy.]

I'm looking for a way to remove "empty" values from a tuple. In other words, say
I have a tuple T:

    tuple<E, int, E, double, E, char, E> T;
    // where E can be either null_type, or mpl::void_, etc.

I'd like for it to collapse into:

    tuple<int, double, char> T2;
 
Now, the reason I say "values" is because I found a way to do just that, but
only for the types, which you'll find below. However, I can't figure out how to
then *construct* the collapsed tuple given the original tuple (and its values.)
Specifically, it's the `???' below that I'm missing.

Thanks!

// Collapse code:

template <typename Sequence>
struct tuple_from_sequence :
    mpl::reverse_fold
        < Sequence
        , tuples::null_type
        , tuples::cons<mpl::_2, mpl::_1>
> {};

template <typename T0, typename T1, typename T2, typename T3, typename T4,
          typename T5, typename T6, typename T7, typename T8, typename T9>
struct collapse <tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> > {
    typedef tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> original;
    typedef mpl::list<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> sequence;

    typedef typename mpl::remove<sequence, tuples::null_type>::type removed;
    typedef typename tuple_from_sequence<removed>::type type;

    static type construct(original const& t) {
        // return ???;
    }
};


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