cpp 中内置/预定义的比较器
最近从STL学习了cpp中的比较器。
我开始知道我们可以使用 greater<>()
作为排序的第三个参数,而不是编写自己的逻辑。
只是想知道 cpp 中有多少内置比较器。
Recently I learnt about comparators in cpp from STL.
I came to know we can use greater<>()
as third argument for sorting instead of writing own logic.
Just curious to know how many inbuilt comparators are there in cpp.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
标准库定义了您所期望的与内置运算符类似的内容:
由于 C++20 还限制了
std::ranges
命名空间中所有这些比较函数对象的版本以及std::compare_third_way
,它类似于内置三向比较运算符<=>
。有关这些函数对象的参考,请参阅 https://en.cppreference.com/ w/cpp/utility/function#Comparisons。
The standard library defines pretty much what you would expect as analogues to the built-in operators:
Since C++20 also constrained versions of all these comparison function objects in the
std::ranges
namespace as well asstd::compare_three_way
, which is the analogue to the built-in three-way comparison operator<=>
.For a reference of these function objects see https://en.cppreference.com/w/cpp/utility/functional#Comparisons.