Boost logo

Boost :

Subject: [boost] [mpl] Using transform problem and solution
From: Edward Diener (eldiener_at_[hidden])
Date: 2011-01-27 21:04:54


I have a boost::mpl::vector of nullary metafunctions and I need to
transform it into a sequence of the metafunction's inner types. As in:

typedef boost::mpl::vector<boost::mpl::identity<int> > tvec;
typedef boost::mpl::vector<int> tvecinner;

So I try boost::mpl::transform:

typedef typename boost::mpl::transform<tvec,_1>::type ttrans;
BOOST_MPL_ASSERT((boost::mpl::equal<tvecinner,ttrans>));

But that does not work and the assert fails. Evidently my _1 is not
working by itself although it seems as if it should because it is a
placeholder expression and its inner type is what I want.

So I try:

template <class T>
struct tself : T
   {
   };

and now instead:

typedef typename boost::mpl::transform<tvec,tself<_1> >::type ttrans;
BOOST_MPL_ASSERT((boost::mpl::equal<tvecinner,ttrans>));

works fine and the assert succeeds.

But that 'tself' hack seems like it should be really unnecessary. Have I
missed something cleaner and easier ?


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk