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

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

本文简介:选择自 pongba 的 blog

        定义:元函数类是指内嵌有名为applypublic 元函数的类。

虽然元函数是模板而非类型,但是元函数类却以一个普通的非模板类将其包覆起来,使其成为一个类型。因为元函数操作和返回的都是类型,所以元函数类也可以被作为参数传递给另一个元函数,而元函数也可以返回一个元函数类。

从而,我们得到了一个plus_f元函数类,将它作为binaryoperation传递给mpl::transform不会导致编译错误:

 

template <class t, class d1, class d2>

quantity<

    t

  , typename mpl::transform<d1,d2,plus_f>::type //new dimensions

> 

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

{

    typedef typename mpl::transform<d1,d2,plus_f>::type dim;

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

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

go top