C++ pair的比较大小

来源:互联网 发布:淘宝的金牌卖家可信吗 编辑:程序博客网 时间:2024/06/03 09:30

std::pair 是可以比较大小的

有这样的全局函数

template<class _Ty1,class _Ty2> inlinebool operator<(const pair<_Ty1, _Ty2>& _Left,const pair<_Ty1, _Ty2>& _Right){// test if _Left < _Right for pairsreturn (_Left.first < _Right.first ||!(_Right.first < _Left.first) && _Left.second < _Right.second);}


也就是说可以比较大小,先按first比较,如果相等,再按照second比较。

0 0
原创粉丝点击