Boost logo

Boost Users :

Subject: [Boost-users] [mpl][variant] Visitor with typelists
From: Tilo Nitzsche (tricorus_at_[hidden])
Date: 2008-12-28 17:39:13


What is the best (shortest/most elegant) way to create a visitor for a Variant, where there are subsets of the variant types, for which the operation is the same?

typedef boost::mpl::vector<A, B, C> v1;
typedef boost::mpl::vector<D, E> v2;
typedef boost::mpl::joint_view<v1, v2> v;
typedef boost::make_variant_over< v >::type v_union;

struct visitor : public boost::static_visitor<int> {
    int operator()([T in v1] arg) { // do something for A, B, C
        return arg.a;
    }
    int operator()([T in v2] arg) { // do something for D, E
        return arg.b;
    }
};

Thanks,
Tilo

      


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