第三章 深度探索元函数 (1)[29]

[入库:2005年8月19日] [更新:2007年3月24日]

本文简介:选择自 pongba 的 blog

 

使用占位符后的operator/像这样:

 

template <class t, class d1, class d2>

quantity<

    t

  , typename mpl::transform<d1,d2,mpl::minus<_1,_2> >::type

> 

operator/(quantity<t,d1> x, quantity<t,d2> y)

{

   typedef typename

     mpl::transform<d1,d2,mpl::minus<_1,_2> >::type dim;

 

   return quantity<t,dim>( x.value() / y.value() );

}

 

代码明显变得更为简洁了(因为用不着额外定义一个minus_f类)。我们还可以将计算新单位的代码分解到一个新的元函数中,这样代码将继续得到简化:

 

本文关键:第三章 深度探索元函数 (1)
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top