首页 > 编程语言 > 详细

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

时间:2017-06-14 21:40:19      阅读:1399      评论:0      收藏:0      [点我收藏+]

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

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

原文:http://www.cnblogs.com/lzhu/p/7010894.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!