基于多个值类型对矢量进行排序
Sorting a vector based on multiple value types
我想根据多个值对自定义结构进行排序。。。我已经处理过一些情况,其中我必须使用<>按2个不同的数字进行排序在自定义排序方法中。。。除了这次我必须按照2个布尔值和一个数字进行排序。
struct MyStruct
{
B1 = false;
B2 = true;
N1 = 0;
}
现在。。。我希望它排序如下。。。
任何B1和B2为真的东西都是第一位的。任何有B1的都是下一个。
这两个部分也需要按N1(较低=先到)进行排序
所以B1和B2需要从N1的最低到最高排序。紧随其后的是B1,N1从最低到最高。紧随其后的是从最低到最高的顺序。
这是我迄今为止的尝试。。。
if (lhs.boss && lhs.isLOS && lhs.distancetome < rhs.distancetome)
return true;
if (lhs.boss && lhs.isLOS && lhs.distancetome > rhs.distancetome)
return false;
if (lhs.boss && lhs.distancetome < rhs.distancetome)
return true;
if (lhs.boss && lhs.distancetome > rhs.distancetome)
return false;
if (lhs.distancetome < rhs.distancetome)
return true;
return false;
类似的东西:
struct complex_comparison
{
bool operator()(const MyStruct& lhs, const MyStruct& rhs)
{
return lhs.B1 && lhs.B2 != rhs.B1 && rhs.B2 ? lhs.B1 && lhs.B2 > rhs.B1 && rhs.B2 :
lhs.B1 != rhs.B1 ? lhs.B1 > rhs.B1 :
lhs.N1 < rhs.N1;
}
};
示例:http://coliru.stacked-crooked.com/a/b4888ac34d2ca6bb
相关文章:
- 按多个属性排序
- 同步对多个向量进行排序
- 对于多个字符(如 ETX/STX 对),是否有类似于 std::quote 的东西
- C++类似于 std::map 的数据结构,具有多个键级别
- 如何将类成员专用于多个模板值(常量)?
- 在单个排序调用C++中对多个向量进行排序
- 对多个数据成员进行排序
- 具有依赖于实现的成员函数类型的多个静态接口
- 根据一个向量对多个向量排序
- GPU cuda 代码是否适用于多个 GPU 卡而无需任何实现
- 一个包含多个OpenCL内核的程序相对于多个分别包含一个内核的程序的优势
- 什么是适用于多个入口和多个出口的类似BFS的最佳路径算法
- 关键部分对象如何精确地适用于多个方法
- STL算法(如for_each)应用于多个参数
- 适用于多个窗口的win32程序
- 适用于多个平台的数据库"tools"
- 配置一个依赖于多个其他CMake项目的CMake项目
- 只有一种材质应用于多个对象
- Jenkins+CMake,适用于多个操作系统和库版本
- WSABUF结构应用于多个应用中