如何将这些数字相加?
typedef boost::mpl::vector<
boost::mpl::int_<1>, boost::mpl::int_<2>,
boost::mpl::int_<3>, boost::mpl::int_<4>,
boost::mpl::int_<5>, boost::mpl::int_<6> > ints;
typedef boost::mpl::accumulate<ints, boost::mpl::int_<0>, ????? >::type sum;发布于 2012-04-16 19:39:58
编辑:我错了,可以直接用mpl::plus,用的是placeholder expressions。这简化了整个符号:
typedef mpl::accumulate<ints, mpl::int_<0>, mpl::plus<mpl::_1, mpl::_2> >::type sum;当然,使用metafunction class也可以获得相同的效果(对于添加来说有点夸张,但对于更复杂的东西可能是合理的):
struct plus_mpl
{
template <class T1, class T2>
struct apply
{
typedef typename mpl::plus<T1,T2>::type type;
};
};
typedef mpl::accumulate<ints, mpl::int_<0>, plus_mpl >::type sum;https://stackoverflow.com/questions/10171314
复制相似问题