
David Abrahams wrote:
Yuval Ronen <ronen_yuval@yahoo.com> 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;
Looks cool, will check it out. Thanks.