2012-04-16 7 views
2

どのように番号を追加しますか?ブーストmpl積分型が累積

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; 

答えて

2

EDIT:私はあなたがplaceholder expressionsを使用して、直接mpl::plusを使用することができ、間違っていました。 (追加するためのやり過ぎですが、より多くの何かのために複合体が合理的であるかもしれない)metafunction classを使用して同じ効果を得ることも可能である。もちろん、

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; 
これは全体の表記法を簡素化