我有一组由3个整数构成的元组,我不想有任何重复。也就是说,我不希望有两个条目具有相同的3个值。
以下是我的代码。
struct Key{
unsigned a;
unsigned b;
unsigned c;
public:
Key(unsigned _a, unsigned _b, unsigned _c) :
a(_a),
b(_b),
c(_c) {}
bool operator<(const Key& rhs) const
{
if (a < rhs.a) {
return true;
}
if (b < rhs.b) {
return true;
}
if (c < rhs.c) {
return true;
}
return false;
};
};
std::set<Key> myset;
但是我有时会在myset
中看到重复项,我无法准确地捕捉到是什么序列导致添加了重复的条目。 它并不总是发生。
我的问题是这样的,我的operator<
函数是否存在内部问题?