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表示内置类型从小到大排序。

posted @ 2017-06-14 20:45  瘋子朱磊  阅读(22647)  评论(4编辑  收藏  举报