我正在尝试按降序排序列表(类的一部分)包含a的项目struct,但它不编译:
错误:'__last - __first'中'operator-'不匹配
sort(Result.poly.begin(), Result.poly.end(), SortDescending());
Run Code Online (Sandbox Code Playgroud)
这是SortDescending:
struct SortDescending
{
bool operator()(const term& t1, const term& t2)
{
return t2.pow < t1.pow;
}
};
Run Code Online (Sandbox Code Playgroud)
谁能告诉我什么是错的?
我刚刚阅读了一篇关于C++概念的(印刷版,德语)文章(C++ 20).
本文使用以下Sortable概念给出了函数模板的示例:
template<typename Cont>
requires Sortable<Cont>()
void sort(Cont& container) { ... }
Run Code Online (Sandbox Code Playgroud)
它声称编译器会拒绝以下代码:
std::list<int> lst = { 1, 7, 5, 12 };
sort(lst);
Run Code Online (Sandbox Code Playgroud)
有一个错误:
错误:lst不是带<的随机访问容器
假设文章是正确的-到底为什么是一个列表的INT值不排序?对我来说,整数的列表就像是在考虑"可排序"的东西时的典型例子?!
不,我不是在询问std :: sort.我在问:为什么Sortable 概念不起作用std::list<int>?
可能重复:
使用stl排序功能排序列表
C++标准库提供严格的线性序列容器,线性序列容器,关联容器.
std::sort()适用于各种容器.但为什么只提供列表排序.std::list::sort()?