开发者

How to use operator> in partial_sort_copy

I hope this is not 开发者_JAVA技巧a noob question - allthough it is my first here on stackoverflow ;)

When using partial_sort_copy with for example 2 vectors, it gives you the "smallest" n values, depending on how operator< is defined for the Class of the T (where n is the size of the target vector)

Is there a possibility to use operator> instead, without defining an extra function?

Thanks in advance :)


You don't have to define an extra function; the C++ Standard Library already has one.

It's called std::greater.

// Where 'T' is the type of object being sorted:
std::partial_sort(input.begin(), input.end(),
                  output.begin(), output.end(), 
                  std::greater<T>()); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜