小编MrN*_*man的帖子

使用元素的投影而不是比较器进行排序

我为此搜索了 c++ 模拟(python):

sorted(vector, key=lambda x : my_function(x))
Run Code Online (Sandbox Code Playgroud)

当然还有构造:

std::sort(vector.begin(), vector.end(), [](const auto& lhs, const auto& rhs) {
    return my_function(lhs) < my_function(rhs);
});
Run Code Online (Sandbox Code Playgroud)

我只是想知道是否存在单参数构造。

c++ sorting projection comparator

5
推荐指数
1
解决办法
695
查看次数

标签 统计

c++ ×1

comparator ×1

projection ×1

sorting ×1