C++之greater和less
生活随笔
收集整理的這篇文章主要介紹了
C++之greater和less
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、greater、 less
他在頭文件<functional>里面, greater和less都重載了操作符 定義如下: // TEMPLATE STRUCT greater template<class _Ty> struct greater : public binary_function<_Ty, _Ty, bool> { // functor for operator>bool operator()(const _Ty& _Left, const _Ty& _Right) const{ // apply operator> to operandsreturn (_Left > _Right);} };// TEMPLATE STRUCT less template<class _Ty> struct less : public binary_function<_Ty, _Ty, bool> { // functor for operator<bool operator()(const _Ty& _Left, const _Ty& _Right) const{ // apply operator< to operandsreturn (_Left < _Right);} };2、Demo測試
我們一般用sort函數的時候,可以作為函數指針傳遞下去,不需要單獨寫比較函數作為函數指針傳遞給sort函數的第三個參數總結
以上是生活随笔為你收集整理的C++之greater和less的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux之vim复制多行、光标跳转到指
- 下一篇: C++之STL之priority_que