C++:greater<int>和less<int>

greater和less是xfunctional.h中的两个结构体,代码如下:

 1 template<class _Ty = void>
 2     struct less
 3     {    // functor for operator<
 4     typedef _Ty first_argument_type;
 5     typedef _Ty second_argument_type;
 6     typedef bool result_type;
 7 
 8     constexpr bool operator()(const _Ty& _Left, const _Ty& _Right) const
 9         {    // apply operator< to operands
10         return (_Left < _Right);
11         }
12     };
 1 template<class _Ty = void>
 2     struct greater
 3     {    // functor for operator>
 4     typedef _Ty first_argument_type;
 5     typedef _Ty second_argument_type;
 6     typedef bool result_type;
 7 
 8     constexpr bool operator()(const _Ty& _Left, const _Ty& _Right) const
 9         {    // apply operator> to operands
10         return (_Left > _Right);
11         }
12     };

greater表示内置类型从大到小排序,less表示内置类型从小到大排序。

原文地址:https://www.cnblogs.com/lzhu/p/7010894.html