std::less()用法及分析分析

来源:互联网 发布:linux账号密码忘记了 编辑:程序博客网 时间:2024/06/07 18:31

使用示例:

#include <iostream>     // std::cout#include <functional>   // std::less#include <algorithm>    // std::sort, std::includesint main(void){      int foo[]={10,20,5,15,25};      std::sort (foo, foo+5, std::less<int>());  // 5 10 15 20 25      for(int i = 0; i< 5; i++)      {          std::cout << "value:"<<foo[i]<<std::endl;      }      return 0;}

结果输出:
这里写图片描述
c++11定义如下:

template <class T> struct less {  bool operator() (const T& x, const T& y) const {return x<y;}  typedef T first_argument_type;  typedef T second_argument_type;  typedef bool result_type;};
0 0
原创粉丝点击