[PATCH] D108733: Use std::less instead of operator < in less_first and less_second

Akira Hatanaka via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 25 15:09:44 PDT 2021


ahatanak created this revision.
ahatanak added reviewers: ldionne, bkramer.
ahatanak added a project: LLVM.
Herald added a subscriber: dexonsmith.
ahatanak requested review of this revision.

According to the standard, if p1 and p2 are both pointers, p1 < p2 and p2 < p1 can both be false in theory in some cases:

https://eel.is/c++draft/expr.rel#4.3

std::less<void> yields a implementation-defined strict total order over pointers:

https://eel.is/c++draft/comparisons.general


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D108733

Files:
  llvm/include/llvm/ADT/STLExtras.h


Index: llvm/include/llvm/ADT/STLExtras.h
===================================================================
--- llvm/include/llvm/ADT/STLExtras.h
+++ llvm/include/llvm/ADT/STLExtras.h
@@ -1273,7 +1273,7 @@
 /// compares less than the first component of another std::pair.
 struct less_first {
   template <typename T> bool operator()(const T &lhs, const T &rhs) const {
-    return lhs.first < rhs.first;
+    return std::less<>()(lhs.first, rhs.first);
   }
 };
 
@@ -1281,7 +1281,7 @@
 /// compares less than the second component of another std::pair.
 struct less_second {
   template <typename T> bool operator()(const T &lhs, const T &rhs) const {
-    return lhs.second < rhs.second;
+    return std::less<>()(lhs.second, rhs.second);
   }
 };
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108733.368747.patch
Type: text/x-patch
Size: 753 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210825/817a7db7/attachment-0001.bin>


More information about the llvm-commits mailing list