2

番号を追加するにはどうすればよいですか?

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;
4

1 に答える 1

3

編集:私は間違っていました、プレースホルダー式mpl::plusを使用して直接使用できます。これにより、表記全体が簡略化されます。

typedef mpl::accumulate<ints, mpl::int_<0>, mpl::plus<mpl::_1, mpl::_2>  >::type sum;

もちろん、メタ関数クラスを使用して同じ効果を得ることができます(追加するのはやり過ぎですが、もっと複雑なものには合理的かもしれません):

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;
于 2012-04-16T11:39:57.580 に答える