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表示內置類型從小到大排序。
