[C++11] Simplify compare operators with std::tie.

No functionality change.

llvm-svn: 202755
This commit is contained in:
Benjamin Kramer 2014-03-03 20:26:46 +00:00
parent b56be64599
commit a741b8c451
8 changed files with 17 additions and 45 deletions

View File

@ -471,11 +471,8 @@ public:
assert(VBase != other.VBase);
return VBTableIndex < other.VBTableIndex;
}
if (VFPtrOffset != other.VFPtrOffset)
return VFPtrOffset < other.VFPtrOffset;
if (Index != other.Index)
return Index < other.Index;
return false;
return std::tie(VFPtrOffset, Index) <
std::tie(other.VFPtrOffset, other.Index);
}
};

View File

@ -87,13 +87,8 @@ public:
/// If not provided, minor and subminor version numbers are considered to be
/// zero.
friend bool operator<(const VersionTuple &X, const VersionTuple &Y) {
if (X.Major != Y.Major)
return X.Major < Y.Major;
if (X.Minor != Y.Minor)
return X.Minor < Y.Minor;
return X.Subminor < Y.Subminor;
return std::tie(X.Major, X.Minor, X.Subminor) <
std::tie(Y.Major, Y.Minor, Y.Subminor);
}
/// \brief Determine whether one version number follows another.

View File

@ -41,20 +41,16 @@ public:
return !(LHS == RHS);
}
friend bool operator<(FileOffset LHS, FileOffset RHS) {
if (LHS.FID != RHS.FID)
return LHS.FID < RHS.FID;
return LHS.Offs < RHS.Offs;
return std::tie(LHS.FID, LHS.Offs) < std::tie(RHS.FID, RHS.Offs);
}
friend bool operator>(FileOffset LHS, FileOffset RHS) {
if (LHS.FID != RHS.FID)
return LHS.FID > RHS.FID;
return LHS.Offs > RHS.Offs;
return RHS < LHS;
}
friend bool operator>=(FileOffset LHS, FileOffset RHS) {
return LHS > RHS || LHS == RHS;
return !(LHS < RHS);
}
friend bool operator<=(FileOffset LHS, FileOffset RHS) {
return LHS < RHS || LHS == RHS;
return !(RHS < LHS);
}
};

View File

@ -97,13 +97,8 @@ public:
/// Unsigned integers are considered to be better conversion types than
/// signed integers of the same width.
bool operator<(const APSIntType &Other) const {
if (BitWidth < Other.BitWidth)
return true;
if (BitWidth > Other.BitWidth)
return false;
if (!IsUnsigned && Other.IsUnsigned)
return true;
return false;
return std::tie(BitWidth, IsUnsigned) <
std::tie(Other.BitWidth, Other.IsUnsigned);
}
};

View File

@ -2156,10 +2156,7 @@ void ItaniumVTableBuilder::dumpLayout(raw_ostream &Out) {
std::sort(ThunksVector.begin(), ThunksVector.end(),
[](const ThunkInfo &LHS, const ThunkInfo &RHS) {
assert(LHS.Method == 0 && RHS.Method == 0);
if (LHS.This != RHS.This)
return LHS.This < RHS.This;
return LHS.Return < RHS.Return;
return std::tie(LHS.This, LHS.Return) < std::tie(RHS.This, RHS.Return);
});
Out << "Thunks for '" << MethodName << "' (" << ThunksVector.size();
@ -3169,9 +3166,7 @@ void VFTableBuilder::dumpLayout(raw_ostream &Out) {
[](const ThunkInfo &LHS, const ThunkInfo &RHS) {
// Keep different thunks with the same adjustments in the order they
// were put into the vector.
if (LHS.This != RHS.This)
return LHS.This < RHS.This;
return LHS.Return < RHS.Return;
return std::tie(LHS.This, LHS.Return) < std::tie(RHS.This, RHS.Return);
});
Out << "Thunks for '" << MethodName << "' (" << ThunksVector.size();

View File

@ -58,11 +58,8 @@ struct MatchKey {
BoundNodesTreeBuilder BoundNodes;
bool operator<(const MatchKey &Other) const {
if (MatcherID != Other.MatcherID)
return MatcherID < Other.MatcherID;
if (Node != Other.Node)
return Node < Other.Node;
return BoundNodes < Other.BoundNodes;
return std::tie(MatcherID, Node, BoundNodes) <
std::tie(Other.MatcherID, Other.Node, Other.BoundNodes);
}
};

View File

@ -99,10 +99,8 @@ namespace CodeGen {
}
bool operator<(const OrderGlobalInits &RHS) const {
if (priority < RHS.priority)
return true;
return priority == RHS.priority && lex_order < RHS.lex_order;
return std::tie(priority, lex_order) <
std::tie(RHS.priority, RHS.lex_order);
}
};

View File

@ -34,8 +34,7 @@ public:
}
bool operator<(const CountKey &RHS) const {
return (CallSite == RHS.CallSite) ? (BlockID < RHS.BlockID)
: (CallSite < RHS.CallSite);
return std::tie(CallSite, BlockID) < std::tie(RHS.CallSite, RHS.BlockID);
}
void Profile(llvm::FoldingSetNodeID &ID) const {