有些人写
std::nth_element(v.begin(), v.begin()+1, v.end(), std::greater{});
还有一些是这样写的std::nth_element(v.begin(), v.begin()+1, v.end(), std::greater<int>());
std::greater{}
之间有什么区别和 std::greater<int>()
?
最佳答案
这是 C++14 的新功能,这导致了两个完全不同的类。
在 C++14 中,std::greater
为其模板参数获取默认值:void
.
您最终会得到 std::greater<void>
或 std::greater<int>
.std::greater<void>
是 so-called "transparent" comparator 的特化推导出其参数,请参阅其引用以获取更多信息。
关于c++ - std::greater{} 和 std::greater<int>() 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68984321/