C++之greater和less
生活随笔
收集整理的這篇文章主要介紹了
C++之greater和less
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
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測(cè)試
我們一般用sort函數(shù)的時(shí)候,可以作為函數(shù)指針傳遞下去,不需要單獨(dú)寫(xiě)比較函數(shù)作為函數(shù)指針傳遞給sort函數(shù)的第三個(gè)參數(shù)總結(jié)
以上是生活随笔為你收集整理的C++之greater和less的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: linux之vim复制多行、光标跳转到指
- 下一篇: C++之STL之priority_que