我有一个以下类型的结构体,我计划将其用作映射中的键。因此,我编写了以下比较器。我想知道是否有更优雅且高效的方法来实现这一点。
也许可以使用
也许可以使用
std::pair
或其他方法。struct T
{
int a, b, c, d;
bool operator< (const T& r) {
if (a < r.a)
return true
else if (a == r.a)
if (b < r.b)
return true;
else if (b == r.b)
if (c < r.c)
return true;
else if (c == r.c)
if (d < r.d)
return true;
return false;
}
}