C++:greater和less

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

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/255307

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月14日 上午8:45
下一篇 2023年2月14日 上午8:45

相关推荐