1. 程式人生 > >std::less()用法及分析分析

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

https://blog.csdn.net/renyican/article/details/50058011

 

使用示例:

#include <iostream>     // std::cout
#include <functional>   // std::less
#include <algorithm>    // std::sort, std::includes
int 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;
};
--------------------- 
作者:renyican 
來源:CSDN 
原文:https://blog.csdn.net/renyican/article/details/50058011 
版權宣告:本文為博主原創文章,轉載請附上博文連結!