该case一般在多个字段时出现,如果两个字段相互小于则100%必现,也是日常工作碰到的case,在此记录下
可以看到 ,SortKey结构的逻辑明显错误。
#include <iostream>
#include <map>
#include <string>
#include <ctime>
#include <stack>
using namespace std;
int main()
{
struct SortKey {
uint64_t ms;
uint32_t uid;
SortKey() :ms(0), uid(0) {}
SortKey(uint64_t _ms, uint32_t _uid) : ms(_ms), uid(_uid) {}
bool operator<(const SortKey& key) const {
//if (ms != key.ms) return ms < key.ms;
//return uid < key.uid;
return ms < key.ms ? true : uid < key.uid;
}
};
struct SortKey2 {
uint64_t ms;
uint32_t uid;
SortKey2() :ms(0), uid(0) {}
SortKey2(uint64_t _ms, uint32_t _uid) : ms(_ms), uid(_uid) {}
bool operator<(const SortKey2& key) const {
if (ms != key.ms) return ms < key.ms;
return uid < key.uid;
//return ms < key.ms ? true : uid < key.uid;
}
};
map<SortKey, string> aa;
SortKey keya, keyb;
keya.ms = 1; keya.uid = 2;
keyb.ms = 2; keyb.uid = 1;
cout << "a,b smaller?:" <<(keya < keyb) << " a,b bigger?:" << (keyb < keya) << " a, b equal?:" << (!(keya < keyb) && !(keyb < keya)) << endl;
SortKey2 keya2, keyb2;
keya2.ms = 1; keya2.uid = 2;
keyb2.ms = 2; keyb2.uid = 1;
cout << "a,b smaller?:" << (keya2 < keyb2) << " a,b bigger?:" << (keyb2 < keya2) << " a, b equal?:" << (!(keya2 < keyb2) && !(keyb2 < keya2)) << endl;
}