
AMDG On 1/27/2011 6:04 PM, Edward Diener wrote:
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.
I would say that the behavior of MPL is correct. Consider what would happen with the runtime Lambda: _1(f) -> f bind(_1)(f) -> f() Here also, using _1 by itself isn't enough to trigger evaluation.
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 ?
mpl::apply<_1>? In Christ, Steven Watanabe