3.2 STL中的函数对象类模板

*:

STL中有一些函数对象类模板,如下所示:

1)例如要求两个double类型的x 和y 的积,可以:

multiplies<double>()(x,y);

该表达式的值就是x*y的值。

2)less是STL中最常用的函数对象类模板,其定义如下:

  template<class _Tp>

  struct less

{

     bool oprator()(const _Tp&_x,const _Tp&_y)const

    {

          return _c<_y;

    }

}

要判断两个int 变量,x 是否比y小,可以编写:

if(kess<int>()(c,y)){....}

 

**:引入函数对象后STL中大小 相等的概念

posted @ 2016-05-09 11:32  党兴明  阅读(283)  评论(0编辑  收藏  举报