Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2006-08-25 19:10:58


Yuval Ronen <ronen_yuval_at_[hidden]> writes:

> Lets say I have several types t1, t2, t3, and so on. Each of them has a
> typedef x within it. I want to be able to get a type y, and find the
> type t which holds is_same<y, t::x>. I thought of doing it using
> mpl::map< pair<t1::x, t1>, pair<t2::x, t2>, ...>.
>
> The problem is how to create the map. I can create it manually, just
> like in the previous sentence, but I hope there's a better way. Is there
> some transform algorithm that I can pass it an mpl::set<t1, t2, ...> and
> a meta-function that yields t::x for any given t, and this algorithm
> would produce the desired map?

  // untested
  template <class T> struct getx { typedef typename T::x type; };

  mpl::fold<
      the_ts
    , mpl::insert<_1, mpl::pair<getx<_2>,_2> >
    , mpl::map0<>
>::type the_map;

HTH,

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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